env_dpdk: save and restore optind in spdk_env_init

DPDK's use of getopt() needs special handling of the optind global
variable since we are passing it a separate array of arguments (not the
typical argv and argc).  Set optind to 1 internally to env_dpdk so that
the apps don't need to know about it, and restore optind in case the
calling app is also using getopt().

Change-Id: Icbf07002c99fa9f94c866e8eff707124b0ef679b
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/365062
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Daniel Verkamp 2017-06-12 12:55:37 -07:00
parent 1f5bbe02cf
commit 9f237eac85
15 changed files with 8 additions and 22 deletions

View File

@ -175,8 +175,6 @@ main(int argc, char **argv)
sleep(10);
}
optind = 1; /* reset the optind */
opts.shutdown_cb = spdk_iscsi_shutdown;
opts.usr1_handler = spdk_sigusr1;
spdk_app_init(&opts);

View File

@ -298,7 +298,7 @@ parse_args(int argc, char **argv)
usage(argv[0]);
return 1;
}
optind = 1;
return 0;
}

View File

@ -275,7 +275,7 @@ parse_args(int argc, char **argv)
usage(argv[0]);
return 1;
}
optind = 1;
return 0;
}

View File

@ -409,7 +409,6 @@ parse_args(int argc, char **argv)
return 1;
}
optind = 1;
return 0;
}

View File

@ -960,8 +960,6 @@ parse_args(int argc, char **argv)
}
}
optind = 1;
return 0;
}

View File

@ -1179,7 +1179,7 @@ parse_args(int argc, char **argv)
}
g_aio_optind = optind;
optind = 1;
return 0;
}

View File

@ -236,6 +236,7 @@ void spdk_env_init(const struct spdk_env_opts *opts)
char **args = NULL;
char **dpdk_args = NULL;
int argcount, i, rc;
int orig_optind;
argcount = spdk_build_eal_cmdline(opts, &args);
if (argcount <= 0) {
@ -262,7 +263,10 @@ void spdk_env_init(const struct spdk_env_opts *opts)
memcpy(dpdk_args, args, sizeof(char *) * argcount);
fflush(stdout);
orig_optind = optind;
optind = 1;
rc = rte_eal_init(argcount, dpdk_args);
optind = orig_optind;
spdk_free_args(args, argcount);
free(dpdk_args);

View File

@ -105,8 +105,6 @@ main(int argc, char **argv)
exit(1);
}
optind = 1; /* reset the optind */
spdk_env_init(&opts);
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n");

View File

@ -714,8 +714,6 @@ main(int argc, char **argv)
g_zcopy = false;
}
optind = 1; /* reset the optind */
blockdev_heads_init();
bdevtest_init(config_file, core_mask);

View File

@ -143,8 +143,6 @@ main(int argc, char **argv)
exit(1);
}
optind = 1; /* reset the optind */
spdk_app_init(&opts);
g_tsc_rate = spdk_get_ticks_hz();

View File

@ -134,8 +134,6 @@ main(int argc, char **argv)
exit(1);
}
optind = 1;
opts.shutdown_cb = test_cleanup;
spdk_app_init(&opts);

View File

@ -130,8 +130,6 @@ main(int argc, char **argv)
exit(1);
}
optind = 1;
opts.shutdown_cb = test_cleanup;
spdk_app_init(&opts);

View File

@ -240,8 +240,6 @@ parse_args(int argc, char **argv)
}
}
optind = 1;
return 0;
}

View File

@ -514,7 +514,7 @@ parse_args(int argc, char **argv)
}
g_aio_optind = optind;
optind = 1;
return 0;
}

View File

@ -485,7 +485,6 @@ parse_args(int argc, char **argv)
g_is_random = 1;
}
optind = 1;
return 0;
}