From 675508f608fbf10297b0060d4ee5e88d86facb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 Jan 2022 00:38:24 +0100 Subject: [PATCH] zpool: wait: only accept whole columns for -t, not col[=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/zpool/zpool_main.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index c1413241f0..de36c4af13 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -10672,9 +10671,7 @@ int zpool_do_wait(int argc, char **argv) { boolean_t verbose = B_FALSE; - int c; - char *value; - int i; + int c, i; unsigned long count; pthread_t status_thr; int error = 0; @@ -10708,28 +10705,26 @@ zpool_do_wait(int argc, char **argv) get_timestamp_arg(*optarg); break; case 't': - { - static char *col_subopts[] = { "discard", "free", - "initialize", "replace", "remove", "resilver", - "scrub", "trim", NULL }; - /* Reset activities array */ memset(&wd.wd_enabled, 0, sizeof (wd.wd_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_opts[] = { + "discard", "free", "initialize", "replace", + "remove", "resilver", "scrub", "trim" }; - wd.wd_enabled[activity] = B_TRUE; + for (i = 0; i < ARRAY_SIZE(col_opts); ++i) + if (strcmp(tok, col_opts[i]) == 0) { + wd.wd_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);