zpool: wait: only accept whole columns for -t, not col[=whatever]

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12996
This commit is contained in:
наб 2022-01-22 00:38:24 +01:00 committed by Brian Behlendorf
parent c21819026f
commit 675508f608
1 changed files with 15 additions and 20 deletions

View File

@ -50,7 +50,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <pwd.h> #include <pwd.h>
@ -10672,9 +10671,7 @@ int
zpool_do_wait(int argc, char **argv) zpool_do_wait(int argc, char **argv)
{ {
boolean_t verbose = B_FALSE; boolean_t verbose = B_FALSE;
int c; int c, i;
char *value;
int i;
unsigned long count; unsigned long count;
pthread_t status_thr; pthread_t status_thr;
int error = 0; int error = 0;
@ -10708,28 +10705,26 @@ zpool_do_wait(int argc, char **argv)
get_timestamp_arg(*optarg); get_timestamp_arg(*optarg);
break; break;
case 't': case 't':
{
static char *col_subopts[] = { "discard", "free",
"initialize", "replace", "remove", "resilver",
"scrub", "trim", NULL };
/* Reset activities array */ /* Reset activities array */
memset(&wd.wd_enabled, 0, sizeof (wd.wd_enabled)); memset(&wd.wd_enabled, 0, sizeof (wd.wd_enabled));
while (*optarg != '\0') {
int activity = getsubopt(&optarg, col_subopts,
&value);
if (activity < 0) { for (char *tok; (tok = strsep(&optarg, ",")); ) {
(void) fprintf(stderr, static const char *const col_opts[] = {
gettext("invalid activity '%s'\n"), "discard", "free", "initialize", "replace",
value); "remove", "resilver", "scrub", "trim" };
usage(B_FALSE);
for (i = 0; i < ARRAY_SIZE(col_opts); ++i)
if (strcmp(tok, col_opts[i]) == 0) {
wd.wd_enabled[i] = B_TRUE;
goto found;
} }
wd.wd_enabled[activity] = B_TRUE; (void) fprintf(stderr,
gettext("invalid activity '%s'\n"), tok);
usage(B_FALSE);
found:;
} }
break; break;
}
case '?': case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"), (void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt); optopt);