app: Add check for duplicated options.

In the documentation we indicate that the application specific opt
string cannot have any overlap with the generic opt string. This change
provides a run-time sanity check to ensure that the user has not broken
this rule.

Change-Id: Iaa0d913ad609276b28d5f6baeb4218113e2bb559
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/422914
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Seth Howell 2018-08-20 15:58:51 -07:00 committed by Jim Harris
parent 1d1496dc0d
commit 766aafcf47

View File

@ -233,6 +233,26 @@ __shutdown_event_cb(void *arg1, void *arg2)
g_spdk_app.shutdown_cb(); g_spdk_app.shutdown_cb();
} }
static int
spdk_app_opts_validate(const char *app_opts)
{
int i = 0, j;
for (i = 0; app_opts[i] != '\0'; i++) {
/* ignore getopt control characters */
if (app_opts[i] == ':' || app_opts[i] == '+' || app_opts[i] == '-') {
continue;
}
for (j = 0; SPDK_APP_GETOPT_STRING[j] != '\0'; j++) {
if (app_opts[i] == SPDK_APP_GETOPT_STRING[j]) {
return app_opts[i];
}
}
}
return 0;
}
void void
spdk_app_opts_init(struct spdk_app_opts *opts) spdk_app_opts_init(struct spdk_app_opts *opts)
{ {
@ -741,6 +761,14 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
app_long_opts_len * sizeof(*app_long_opts)); app_long_opts_len * sizeof(*app_long_opts));
} }
if (app_getopt_str != NULL) {
ch = spdk_app_opts_validate(app_getopt_str);
if (ch) {
fprintf(stderr, "Duplicated option '%c' between the generic and application specific spdk opts.\n",
ch);
return SPDK_APP_PARSE_ARGS_FAIL;
}
}
snprintf(g_cmdline_short_opts, sizeof(g_cmdline_short_opts), snprintf(g_cmdline_short_opts, sizeof(g_cmdline_short_opts),
"%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING); "%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);