Commit 766aafcf authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

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: default avatarSeth 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 1d1496dc
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -233,6 +233,26 @@ __shutdown_event_cb(void *arg1, void *arg2)
	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
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));
	}

	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),
		 "%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);