zpool: get: only accept whole columns for -o, 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:
parent
675508f608
commit
66cd170db3
|
@ -518,7 +518,7 @@ print_vdev_prop_cb(int prop, void *cb)
|
||||||
* that command. Otherwise, iterate over the entire command table and display
|
* that command. Otherwise, iterate over the entire command table and display
|
||||||
* a complete usage message.
|
* a complete usage message.
|
||||||
*/
|
*/
|
||||||
static void
|
static _Noreturn void
|
||||||
usage(boolean_t requested)
|
usage(boolean_t requested)
|
||||||
{
|
{
|
||||||
FILE *fp = requested ? stdout : stderr;
|
FILE *fp = requested ? stdout : stderr;
|
||||||
|
@ -10069,7 +10069,6 @@ zpool_do_get(int argc, char **argv)
|
||||||
zprop_list_t fake_name = { 0 };
|
zprop_list_t fake_name = { 0 };
|
||||||
int ret;
|
int ret;
|
||||||
int c, i;
|
int c, i;
|
||||||
char *value;
|
|
||||||
char *propstr = NULL;
|
char *propstr = NULL;
|
||||||
|
|
||||||
cb.cb_first = B_TRUE;
|
cb.cb_first = B_TRUE;
|
||||||
|
@ -10098,10 +10097,14 @@ zpool_do_get(int argc, char **argv)
|
||||||
case 'o':
|
case 'o':
|
||||||
memset(&cb.cb_columns, 0, sizeof (cb.cb_columns));
|
memset(&cb.cb_columns, 0, sizeof (cb.cb_columns));
|
||||||
i = 0;
|
i = 0;
|
||||||
while (*optarg != '\0') {
|
|
||||||
static char *col_subopts[] =
|
for (char *tok; (tok = strsep(&optarg, ",")); ) {
|
||||||
|
static const char *const col_opts[] =
|
||||||
{ "name", "property", "value", "source",
|
{ "name", "property", "value", "source",
|
||||||
"all", NULL };
|
"all" };
|
||||||
|
static const zfs_get_column_t col_cols[] =
|
||||||
|
{ GET_COL_NAME, GET_COL_PROPERTY, GET_COL_VALUE,
|
||||||
|
GET_COL_SOURCE };
|
||||||
|
|
||||||
if (i == ZFS_GET_NCOLS) {
|
if (i == ZFS_GET_NCOLS) {
|
||||||
(void) fprintf(stderr, gettext("too "
|
(void) fprintf(stderr, gettext("too "
|
||||||
|
@ -10110,21 +10113,16 @@ zpool_do_get(int argc, char **argv)
|
||||||
usage(B_FALSE);
|
usage(B_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (getsubopt(&optarg, col_subopts,
|
for (c = 0; c < ARRAY_SIZE(col_opts); ++c)
|
||||||
&value)) {
|
if (strcmp(tok, col_opts[c]) == 0)
|
||||||
case 0:
|
goto found;
|
||||||
cb.cb_columns[i++] = GET_COL_NAME;
|
|
||||||
break;
|
(void) fprintf(stderr,
|
||||||
case 1:
|
gettext("invalid column name '%s'\n"), tok);
|
||||||
cb.cb_columns[i++] = GET_COL_PROPERTY;
|
usage(B_FALSE);
|
||||||
break;
|
|
||||||
case 2:
|
found:
|
||||||
cb.cb_columns[i++] = GET_COL_VALUE;
|
if (c >= 4) {
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
cb.cb_columns[i++] = GET_COL_SOURCE;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
gettext("\"all\" conflicts "
|
gettext("\"all\" conflicts "
|
||||||
|
@ -10132,18 +10130,12 @@ zpool_do_get(int argc, char **argv)
|
||||||
"given to -o option\n"));
|
"given to -o option\n"));
|
||||||
usage(B_FALSE);
|
usage(B_FALSE);
|
||||||
}
|
}
|
||||||
cb.cb_columns[0] = GET_COL_NAME;
|
|
||||||
cb.cb_columns[1] = GET_COL_PROPERTY;
|
memcpy(cb.cb_columns, col_cols,
|
||||||
cb.cb_columns[2] = GET_COL_VALUE;
|
sizeof (col_cols));
|
||||||
cb.cb_columns[3] = GET_COL_SOURCE;
|
|
||||||
i = ZFS_GET_NCOLS;
|
i = ZFS_GET_NCOLS;
|
||||||
break;
|
} else
|
||||||
default:
|
cb.cb_columns[i++] = col_cols[c];
|
||||||
(void) fprintf(stderr,
|
|
||||||
gettext("invalid column name "
|
|
||||||
"'%s'\n"), value);
|
|
||||||
usage(B_FALSE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
|
|
Loading…
Reference in New Issue