diff options
author | Tino Reichardt <[email protected]> | 2023-04-05 18:57:01 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2023-04-05 09:57:01 -0700 |
commit | 6ecdd35bdbcdeae0adabefe107677620e88d5548 (patch) | |
tree | abbbed21514d59fd02e69ae130496cb2cceba5ed /cmd | |
parent | 3399a30ee02d0d31ba2d43d0ce0a2fd90d5c575d (diff) |
Fix "Add colored output to zfs list"
Running `zfs list -o avail rpool` resulted in a core dump.
This commit will fix this.
Run the needed overhead only, when `use_color()` is true.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: George Wilson <[email protected]>
Signed-off-by: Tino Reichardt <[email protected]>
Closes #14712
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zfs/zfs_main.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index f918036cb..d65b01579 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -3556,8 +3556,21 @@ print_dataset(zfs_handle_t *zhp, list_cbdata_t *cb) right_justify = B_FALSE; } - if (pl->pl_prop == ZFS_PROP_AVAILABLE) - color_start(zfs_list_avail_color(zhp)); + /* + * zfs_list_avail_color() needs ZFS_PROP_AVAILABLE + USED + * - so we need another for() search for the USED part + * - when no colors wanted, we can skip the whole thing + */ + if (use_color() && pl->pl_prop == ZFS_PROP_AVAILABLE) { + zprop_list_t *pl2 = cb->cb_proplist; + for (; pl2 != NULL; pl2 = pl2->pl_next) { + if (pl2->pl_prop == ZFS_PROP_USED) { + color_start(zfs_list_avail_color(zhp)); + /* found it, no need for more loops */ + break; + } + } + } /* * If this is being called in scripted mode, or if this is the |