From: Sami Kerola Date: Sat, 11 Jun 2011 14:45:53 +0000 (+0200) Subject: namei: fix to argument handling X-Git-Tag: v2.20-rc1~138^2~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a0d9255698ba5e13e392bdef04d7a51269e6e3a;p=thirdparty%2Futil-linux.git namei: fix to argument handling Missing pathname argument can only be checked after options are parsed. Earlier for example 'namei -l' print nothing and was successful. The option parsing is changed to be less POSIXLY_CORRECT and continue if nonoption argument is found, which allows users to define options and arguments in the order they prefer. Unknown short options, which earlier matched case '?' that was help option alias, are now made to indicate failure in return value. Signed-off-by: Sami Kerola --- diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 0db4c42954..e192f58c15 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -441,7 +441,6 @@ static const struct option longopts[] = int main(int argc, char **argv) { - extern int optind; int c; int rc = EXIT_SUCCESS; @@ -449,13 +448,9 @@ main(int argc, char **argv) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - if (argc < 2) - usage(EXIT_FAILURE); - - while ((c = getopt_long(argc, argv, "+h?Vlmnovx", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "hVlmnovx", longopts, NULL)) != -1) { switch(c) { case 'h': - case '?': usage(EXIT_SUCCESS); break; case 'V': @@ -479,9 +474,17 @@ main(int argc, char **argv) break; case 'v': flags |= NAMEI_VERTICAL; + break; + default: + usage(EXIT_FAILURE); } } + if (optind == argc) { + warnx(_("pathname argument is missing")); + usage(EXIT_FAILURE); + } + for(; optind < argc; optind++) { char *path = argv[optind]; struct namei *nm = NULL;