]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
namei: fix to argument handling
authorSami Kerola <kerolasa@iki.fi>
Sat, 11 Jun 2011 14:45:53 +0000 (16:45 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 25 Jun 2011 10:37:37 +0000 (12:37 +0200)
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 <kerolasa@iki.fi>
misc-utils/namei.c

index 0db4c429543535609b9d5c23404f289e8d8b7f43..e192f58c157560e0884e11724317f29c227a85c3 100644 (file)
@@ -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;