From: Zbigniew Jędrzejewski-Szmek Date: Mon, 15 Feb 2021 09:56:28 +0000 (+0100) Subject: systemctl: hide legends with --quiet, allow overriding X-Git-Tag: v248-rc1~68^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6906da26926365b6b8c06cd81f1dac4f49288041;p=thirdparty%2Fsystemd.git systemctl: hide legends with --quiet, allow overriding --no-legend is replaced by --legend=no. --quiet now implies --legend=no, but --legend=yes may be used to override that. --quiet controls hints and warnings and such, and --legend controls just the legends. I think it makes sense to allow both to controlled independently, in particular --quiet --legend makes sense when using systemctl in a script to provide some user-visible output. Fixes #18560. --- diff --git a/man/standard-options.xml b/man/standard-options.xml index 4565a43b244..d42f3296cab 100644 --- a/man/standard-options.xml +++ b/man/standard-options.xml @@ -35,6 +35,15 @@ Do not query the user for authentication for privileged operations. + + BOOL + + + Enable or disable printing of the legend, i.e. column headers and the footer with hints. The + legend is printed by default, unless disabled with or similar. + + + diff --git a/man/systemctl.xml b/man/systemctl.xml index 2ed58eb33be..b97c5e90fee 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -2314,7 +2314,7 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err - + diff --git a/src/systemctl/systemctl-list-jobs.c b/src/systemctl/systemctl-list-jobs.c index 8b028c013ae..62d99671a55 100644 --- a/src/systemctl/systemctl-list-jobs.c +++ b/src/systemctl/systemctl-list-jobs.c @@ -65,7 +65,7 @@ static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n assert(n == 0 || jobs); if (n == 0) { - if (!arg_no_legend) { + if (arg_legend != 0) { on = ansi_highlight_green(); off = ansi_normal(); @@ -80,7 +80,7 @@ static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n if (!table) return log_oom(); - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_full) table_set_width(table, 0); @@ -112,7 +112,7 @@ static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n if (r < 0) return log_error_errno(r, "Failed to print the table: %m"); - if (!arg_no_legend) { + if (arg_legend != 0) { on = ansi_highlight(); off = ansi_normal(); diff --git a/src/systemctl/systemctl-list-machines.c b/src/systemctl/systemctl-list-machines.c index 48d0e8bde47..712ee8a86b1 100644 --- a/src/systemctl/systemctl-list-machines.c +++ b/src/systemctl/systemctl-list-machines.c @@ -160,7 +160,7 @@ static int output_machines_list(struct machine_info *machine_infos, unsigned n) if (!table) return log_oom(); - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_plain) { /* Hide the 'glyph' column when --plain is requested */ r = table_hide_column_from_display(table, 0); @@ -213,7 +213,7 @@ static int output_machines_list(struct machine_info *machine_infos, unsigned n) if (r < 0) return r; - if (!arg_no_legend) { + if (arg_legend != 0) { printf("\n"); if (state_missing && geteuid() != 0) printf("Notice: some information only available to privileged users was not shown.\n"); diff --git a/src/systemctl/systemctl-list-unit-files.c b/src/systemctl/systemctl-list-unit-files.c index e1bf8766205..95911172a3a 100644 --- a/src/systemctl/systemctl-list-unit-files.c +++ b/src/systemctl/systemctl-list-unit-files.c @@ -58,7 +58,7 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) { if (!table) return log_oom(); - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_full) table_set_width(table, 0); @@ -127,7 +127,7 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) { if (r < 0) return r; - if (!arg_no_legend) + if (arg_legend != 0) printf("\n%u unit files listed.\n", c); return 0; diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c index 7f0e79eedd6..4106c2b1a48 100644 --- a/src/systemctl/systemctl-list-units.c +++ b/src/systemctl/systemctl-list-units.c @@ -97,7 +97,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { if (!table) return log_oom(); - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_plain) { /* Hide the 'glyph' column when --plain is requested */ r = table_hide_column_from_display(table, 0); @@ -177,7 +177,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { if (r < 0) return r; - if (!arg_no_legend) { + if (arg_legend != 0) { const char *on, *off; size_t records = table_get_rows(table) - 1; @@ -366,7 +366,7 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { return log_error_errno(r, "Failed to set columns to display: %m"); } - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_full) table_set_width(table, 0); @@ -417,7 +417,7 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { if (r < 0) return r; - if (!arg_no_legend) { + if (arg_legend != 0) { printf("\n%s%u sockets listed.%s\n", on, cs, off); if (!arg_all) printf("Pass --all to see loaded but inactive sockets, too.\n"); @@ -614,7 +614,7 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) { if (!table) return log_oom(); - table_set_header(table, !arg_no_legend); + table_set_header(table, arg_legend != 0); if (arg_full) table_set_width(table, 0); @@ -659,7 +659,7 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) { if (r < 0) return r; - if (!arg_no_legend) { + if (arg_legend != 0) { printf("\n%s%u timers listed.%s\n", on, n, off); if (!arg_all) printf("Pass --all to see loaded but inactive timers, too.\n"); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 08a54a469e7..f3a784db33f 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -68,7 +68,7 @@ const char *arg_job_mode = "replace"; UnitFileScope arg_scope = UNIT_FILE_SYSTEM; bool arg_wait = false; bool arg_no_block = false; -bool arg_no_legend = false; +int arg_legend = -1; /* -1: true, unless --quiet is passed, 1: true */ PagerFlags arg_pager_flags = 0; bool arg_no_wtmp = false; bool arg_no_sync = false; @@ -267,7 +267,7 @@ static int systemctl_help(void) { " --no-block Do not wait until operation finished\n" " --no-wall Don't send wall message before halt/power-off/reboot\n" " --no-reload Don't reload daemon after en-/dis-abling unit files\n" - " --no-legend Do not print a legend (column headers and hints)\n" + " --legend=BOOL Enable/disable the legend (column headers and hints)\n" " --no-pager Do not pipe output into a pager\n" " --no-ask-password Do not ask for system passwords\n" " --global Enable/disable/mask unit files globally\n" @@ -308,88 +308,89 @@ static int systemctl_help(void) { } static void help_types(void) { - if (!arg_no_legend) + if (arg_legend != 0) puts("Available unit types:"); DUMP_STRING_TABLE(unit_type, UnitType, _UNIT_TYPE_MAX); } static void help_states(void) { - if (!arg_no_legend) + if (arg_legend != 0) puts("Available unit load states:"); DUMP_STRING_TABLE(unit_load_state, UnitLoadState, _UNIT_LOAD_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable unit active states:"); DUMP_STRING_TABLE(unit_active_state, UnitActiveState, _UNIT_ACTIVE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable unit file states:"); DUMP_STRING_TABLE(unit_file_state, UnitFileState, _UNIT_FILE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable automount unit substates:"); DUMP_STRING_TABLE(automount_state, AutomountState, _AUTOMOUNT_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable device unit substates:"); DUMP_STRING_TABLE(device_state, DeviceState, _DEVICE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable mount unit substates:"); DUMP_STRING_TABLE(mount_state, MountState, _MOUNT_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable path unit substates:"); DUMP_STRING_TABLE(path_state, PathState, _PATH_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable scope unit substates:"); DUMP_STRING_TABLE(scope_state, ScopeState, _SCOPE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable service unit substates:"); DUMP_STRING_TABLE(service_state, ServiceState, _SERVICE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable slice unit substates:"); DUMP_STRING_TABLE(slice_state, SliceState, _SLICE_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable socket unit substates:"); DUMP_STRING_TABLE(socket_state, SocketState, _SOCKET_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable swap unit substates:"); DUMP_STRING_TABLE(swap_state, SwapState, _SWAP_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable target unit substates:"); DUMP_STRING_TABLE(target_state, TargetState, _TARGET_STATE_MAX); - if (!arg_no_legend) + if (arg_legend != 0) puts("\nAvailable timer unit substates:"); DUMP_STRING_TABLE(timer_state, TimerState, _TIMER_STATE_MAX); } static int systemctl_parse_argv(int argc, char *argv[]) { enum { - ARG_FAIL = 0x100, + ARG_FAIL = 0x100, /* compatibility only */ ARG_REVERSE, ARG_AFTER, ARG_BEFORE, ARG_CHECK_INHIBITORS, ARG_DRY_RUN, ARG_SHOW_TYPES, - ARG_IRREVERSIBLE, - ARG_IGNORE_DEPENDENCIES, + ARG_IRREVERSIBLE, /* compatibility only */ + ARG_IGNORE_DEPENDENCIES, /* compatibility only */ ARG_VALUE, ARG_VERSION, ARG_USER, ARG_SYSTEM, ARG_GLOBAL, ARG_NO_BLOCK, - ARG_NO_LEGEND, + ARG_LEGEND, + ARG_NO_LEGEND, /* compatibility only */ ARG_NO_PAGER, ARG_NO_WALL, ARG_ROOT, @@ -440,7 +441,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "global", no_argument, NULL, ARG_GLOBAL }, { "wait", no_argument, NULL, ARG_WAIT }, { "no-block", no_argument, NULL, ARG_NO_BLOCK }, - { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, + { "legend", required_argument, NULL, ARG_LEGEND }, + { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, /* compatibility only */ { "no-pager", no_argument, NULL, ARG_NO_PAGER }, { "no-wall", no_argument, NULL, ARG_NO_WALL }, { "dry-run", no_argument, NULL, ARG_DRY_RUN }, @@ -626,7 +628,14 @@ static int systemctl_parse_argv(int argc, char *argv[]) { break; case ARG_NO_LEGEND: - arg_no_legend = true; + arg_legend = false; + break; + + case ARG_LEGEND: + r = parse_boolean_argument("--legend", optarg, NULL); + if (r < 0) + return r; + arg_legend = r; break; case ARG_NO_PAGER: @@ -659,6 +668,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) { case 'q': arg_quiet = true; + + if (arg_legend < 0) + arg_legend = false; + break; case 'f': @@ -717,7 +730,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { optarg); if (OUTPUT_MODE_IS_JSON(arg_output)) { - arg_no_legend = true; + arg_legend = false; arg_plain = true; } break; diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h index 0ebe4580c60..de463db9d5a 100644 --- a/src/systemctl/systemctl.h +++ b/src/systemctl/systemctl.h @@ -52,7 +52,7 @@ extern const char *arg_job_mode; extern UnitFileScope arg_scope; extern bool arg_wait; extern bool arg_no_block; -extern bool arg_no_legend; +extern int arg_legend; extern PagerFlags arg_pager_flags; extern bool arg_no_wtmp; extern bool arg_no_sync; diff --git a/test/fuzz/fuzz-systemctl-parse-argv/help.input b/test/fuzz/fuzz-systemctl-parse-argv/help.input index be0631301b6..db9d80a09f8 100644 Binary files a/test/fuzz/fuzz-systemctl-parse-argv/help.input and b/test/fuzz/fuzz-systemctl-parse-argv/help.input differ