]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: hide legends with --quiet, allow overriding
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2021 09:56:28 +0000 (10:56 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 17 Feb 2021 20:09:14 +0000 (21:09 +0100)
--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.

man/standard-options.xml
man/systemctl.xml
src/systemctl/systemctl-list-jobs.c
src/systemctl/systemctl-list-machines.c
src/systemctl/systemctl-list-unit-files.c
src/systemctl/systemctl-list-units.c
src/systemctl/systemctl.c
src/systemctl/systemctl.h
test/fuzz/fuzz-systemctl-parse-argv/help.input

index 4565a43b2449966b413eb585a8829a710273b054..d42f3296cab4a0bcba0a8491f143f85e7d07f9c0 100644 (file)
     <listitem><para>Do not query the user for authentication for privileged operations.</para></listitem>
   </varlistentry>
 
+  <varlistentry id='legend'>
+    <term><option>--legend=</option><replaceable>BOOL</replaceable></term>
+
+    <listitem>
+      <para>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 <option>--quiet</option> or similar.</para>
+    </listitem>
+  </varlistentry>
+
   <varlistentry id='no-legend'>
     <term><option>--no-legend</option></term>
 
index 2ed58eb33be95a3d64d14efdc8cb4589dceabc19..b97c5e90feee614943517b695c53428109294d68 100644 (file)
@@ -2314,7 +2314,7 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
       <xi:include href="user-system-options.xml" xpointer="machine" />
 
       <xi:include href="standard-options.xml" xpointer="no-pager" />
-      <xi:include href="standard-options.xml" xpointer="no-legend" />
+      <xi:include href="standard-options.xml" xpointer="legend" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
     </variablelist>
index 8b028c013aef23591a940c33baec72c6da4966c3..62d99671a5504bd4fe5a0433eb672847a07c3ee2 100644 (file)
@@ -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();
 
index 48d0e8bde477673b53b4be38ccbaa05b5bceebe3..712ee8a86b18650e86e1803440842cc45f1fcf8c 100644 (file)
@@ -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");
index e1bf8766205b1fa4710079d037a299aa0c7f2b19..95911172a3ad9d99ad287884881346e21d6f70ef 100644 (file)
@@ -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;
index 7f0e79eedd6c34242c5d38d777c9299652d9875f..4106c2b1a483a72672a4c8c15ada59bb0ba8e510 100644 (file)
@@ -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");
index 08a54a469e70c53ea41fa7828403d5c93295bde7..f3a784db33f61c7454e9fad98422515189b7bd3f 100644 (file)
@@ -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;
index 0ebe4580c6027b7c11122f48bcab6c4ebfa2fc0f..de463db9d5a1e3c29e1536ddb3623092b3086aa5 100644 (file)
@@ -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;
index be0631301b69721b8054f04f9144e5d0b9f8afc4..db9d80a09f8a28f374a09bd7982dbdce215e6194 100644 (file)
Binary files a/test/fuzz/fuzz-systemctl-parse-argv/help.input and b/test/fuzz/fuzz-systemctl-parse-argv/help.input differ