aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zfs/zfs_main.c
diff options
context:
space:
mode:
authorGeorge Melikov <[email protected]>2017-02-01 01:41:23 +0300
committerBrian Behlendorf <[email protected]>2017-01-31 14:41:23 -0800
commita873815b95a4a66294c31db70cdce0e1a6ff650f (patch)
tree1971c119312729baf436c573d04d0d619023e799 /cmd/zfs/zfs_main.c
parentd69a321e567bf57c08f243969031545866abaf9d (diff)
OpenZFS 7742 - zfs send wrong error message with invalid long opts
There are two cases: 1. if an invalid flag is passed, and 2. if a valid flag is not given a parameter. In the case of (1), the flag is either short or long. For short flags, optopt contains the character of the flag. For long, it contains zero, and we can access the long flag using argv and optind. In the case of (2), if the flag is short, optopt contains the character of the flag. If the flag is long, the value in the 4th column of the long_options table, for that flag, is returned. We could case over all those values, or we could simply use argv and optind again. Note that in the case of something like `--resume`, which is also `-t`, "t" will be returned if an argument is not provided; so the error message will say `'t': argument not provided` or similar. This could be fixed by making it so long and short options don't use the same character flag, and then combining them in the switch/case statement, but I didn't think the ugliness of the code would be worth the small usability enhancement. Authored by: Paul Dagnelie <[email protected]> Reviewed by: Dan Kimmel <[email protected]> Reviewed by: Steve Gonczi <[email protected]> Reviewed by: Robert Mustacchi <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Ported-by: George Melikov <[email protected]> OpenZFS-issue: https://www.illumos.org/issues/7742 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/6d69b40 Closes #5702
Diffstat (limited to 'cmd/zfs/zfs_main.c')
-rw-r--r--cmd/zfs/zfs_main.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c
index 2a7525758..952244b9f 100644
--- a/cmd/zfs/zfs_main.c
+++ b/cmd/zfs/zfs_main.c
@@ -3820,13 +3820,42 @@ zfs_do_send(int argc, char **argv)
flags.compress = B_TRUE;
break;
case ':':
- (void) fprintf(stderr, gettext("missing argument for "
- "'%c' option\n"), optopt);
+ /*
+ * If a parameter was not passed, optopt contains the
+ * value that would normally lead us into the
+ * appropriate case statement. If it's > 256, then this
+ * must be a longopt and we should look at argv to get
+ * the string. Otherwise it's just the character, so we
+ * should use it directly.
+ */
+ if (optopt <= UINT8_MAX) {
+ (void) fprintf(stderr,
+ gettext("missing argument for '%c' "
+ "option\n"), optopt);
+ } else {
+ (void) fprintf(stderr,
+ gettext("missing argument for '%s' "
+ "option\n"), argv[optind - 1]);
+ }
usage(B_FALSE);
break;
case '?':
- (void) fprintf(stderr, gettext("invalid option '%c'\n"),
- optopt);
+ /*FALLTHROUGH*/
+ default:
+ /*
+ * If an invalid flag was passed, optopt contains the
+ * character if it was a short flag, or 0 if it was a
+ * longopt.
+ */
+ if (optopt != 0) {
+ (void) fprintf(stderr,
+ gettext("invalid option '%c'\n"), optopt);
+ } else {
+ (void) fprintf(stderr,
+ gettext("invalid option '%s'\n"),
+ argv[optind - 1]);
+
+ }
usage(B_FALSE);
}
}