]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: split out helper for --what and allow resetting
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 13 May 2026 15:32:44 +0000 (17:32 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 14 May 2026 07:03:13 +0000 (09:03 +0200)
Analogous to parent commit.

man/systemctl.xml
src/systemctl/systemctl.c

index a6d295927ae59d1bc38cda4ed32a9ab1c2db128c..ce485aee14fa75f8fd0dc9e8c6ec4ab749fc6679 100644 (file)
@@ -2578,10 +2578,12 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
           <constant>all</constant> as a shortcut for specifying all six resource types. If this option is not
           specified defaults to the combination of <constant>cache</constant>, <constant>runtime</constant>
           and <constant>fdstore</constant>, i.e. the three kinds of resources that are generally considered
-          to be redundant and can be reconstructed on next invocation. Note that the explicit removal of the
-          <constant>fdstore</constant> resource type is only useful if the
-          <varname>FileDescriptorStorePreserve=</varname> option is enabled, since the file descriptor store
-          is otherwise cleaned automatically when the unit is stopped.</para>
+          to be redundant and can be reconstructed on next invocation. The empty argument can be used to
+          reset to this default.</para>
+
+          <para>Note that the explicit removal of the <constant>fdstore</constant> resource type is only
+          useful if the <varname>FileDescriptorStorePreserve=</varname> option is enabled, since the file
+          descriptor store is otherwise cleaned automatically when the unit is stopped.</para>
 
           <xi:include href="version-info.xml" xpointer="v243"/>
         </listitem>
index 5c90092f2af380a425400e58ab0f9ccf48493dfe..632e54256cb8d0b37a7d7124378adc0482a070b3 100644 (file)
@@ -498,6 +498,46 @@ static int parse_types_argument(const char *value, char ***types, char ***states
         return 1;
 }
 
+static int parse_what_argument(const char *value, char ***clean_what) {
+        int r;
+
+        assert(value);
+        assert(clean_what);
+
+        if (isempty(value)) {
+                /* reset the setting */
+                *clean_what = strv_free(*clean_what);
+                return 1;
+        }
+
+        for (const char *p = value;;) {
+                _cleanup_free_ char *k = NULL;
+
+                r = extract_first_word(&p, &k, ",", /* flags= */ 0);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse --what=: %m");
+                if (r == 0)
+                        break;
+
+                if (streq(k, "help")) {
+                        puts("runtime\n"
+                             "state\n"
+                             "cache\n"
+                             "logs\n"
+                             "configuration\n"
+                             "fdstore\n"
+                             "all");
+                        return 0;
+                }
+
+                r = strv_consume(clean_what, TAKE_PTR(k));
+                if (r < 0)
+                        return log_oom();
+        }
+
+        return 1;
+}
+
 static int systemctl_parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_FAIL = 0x100,            /* compatibility only */
@@ -967,34 +1007,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_WHAT:
-                        if (isempty(optarg))
-                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--what= requires arguments (see --what=help).");
-
-                        for (const char *p = optarg;;) {
-                                _cleanup_free_ char *k = NULL;
-
-                                r = extract_first_word(&p, &k, ",", 0);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to parse directory type: %s", optarg);
-                                if (r == 0)
-                                        break;
-
-                                if (streq(k, "help")) {
-                                        puts("runtime\n"
-                                             "state\n"
-                                             "cache\n"
-                                             "logs\n"
-                                             "configuration\n"
-                                             "fdstore\n"
-                                             "all");
-                                        return 0;
-                                }
-
-                                r = strv_consume(&arg_clean_what, TAKE_PTR(k));
-                                if (r < 0)
-                                        return log_oom();
-                        }
-
+                        r = parse_what_argument(optarg, &arg_clean_what);
+                        if (r <= 0)
+                                return r;
                         break;
 
                 case ARG_REBOOT_ARG: