diff options
author | Sami Kerola | 2011-06-11 16:45:53 +0200 |
---|---|---|
committer | Sami Kerola | 2011-06-25 12:37:37 +0200 |
commit | 5a0d9255698ba5e13e392bdef04d7a51269e6e3a (patch) | |
tree | 9386b9a1d0cc04a81d85a33ae9270727541e6913 /misc-utils/namei.c | |
parent | namei: use xalloc.h (diff) | |
download | kernel-qcow2-util-linux-5a0d9255698ba5e13e392bdef04d7a51269e6e3a.tar.gz kernel-qcow2-util-linux-5a0d9255698ba5e13e392bdef04d7a51269e6e3a.tar.xz kernel-qcow2-util-linux-5a0d9255698ba5e13e392bdef04d7a51269e6e3a.zip |
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 <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/namei.c')
-rw-r--r-- | misc-utils/namei.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 0db4c4295..e192f58c1 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; |