Skip to content
Snippets Groups Projects
Commit a5ef3505 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Kevin Wolf
Browse files

storage-daemon: report unexpected arguments on the fly


If the first character of optstring is '-', then each nonoption argv
element is handled as if it were the argument of an option with character
code 1.  This removes the reordering of the argv array, and enables usage
of loc_set_cmdline to provide better error messages.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210301152844.291799-2-pbonzini@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 3b6ad623
No related branches found
No related tags found
No related merge requests found
......@@ -174,7 +174,7 @@ static void process_options(int argc, char *argv[])
* they are given on the command lines. This means that things must be
* defined first before they can be referenced in another option.
*/
while ((c = getopt_long(argc, argv, "hT:V", long_options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "-hT:V", long_options, NULL)) != -1) {
switch (c) {
case '?':
exit(EXIT_FAILURE);
......@@ -275,14 +275,13 @@ static void process_options(int argc, char *argv[])
qobject_unref(args);
break;
}
case 1:
error_report("Unexpected argument: %s", optarg);
exit(EXIT_FAILURE);
default:
g_assert_not_reached();
}
}
if (optind != argc) {
error_report("Unexpected argument: %s", argv[optind]);
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment