From 15aca3ad5976a426b416645e6274a22bdd94c756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 Jan 2022 23:12:54 +0100 Subject: [PATCH] zfs: wait: only accept whole activity for -t, not act[=whatever] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12996 --- cmd/zfs/zfs_main.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 938fd2edd5..2a16bd0b49 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -8503,27 +8503,25 @@ zfs_do_wait(int argc, char **argv) while ((c = getopt(argc, argv, "t:")) != -1) { switch (c) { case 't': - { - static char *col_subopts[] = { "deleteq", NULL }; - char *value; - /* Reset activities array */ memset(&enabled, 0, sizeof (enabled)); - while (*optarg != '\0') { - int activity = getsubopt(&optarg, col_subopts, - &value); - if (activity < 0) { - (void) fprintf(stderr, - gettext("invalid activity '%s'\n"), - value); - usage(B_FALSE); - } + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const col_subopts[ + ZFS_WAIT_NUM_ACTIVITIES] = { "deleteq" }; - enabled[activity] = B_TRUE; + for (i = 0; i < ARRAY_SIZE(col_subopts); ++i) + if (strcmp(tok, col_subopts[i]) == 0) { + enabled[i] = B_TRUE; + goto found; + } + + (void) fprintf(stderr, + gettext("invalid activity '%s'\n"), tok); + usage(B_FALSE); +found:; } break; - } case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt);