systemctl: split out helper for --what and allow resetting

Analogous to parent commit.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-05-14 09:03:13 +02:00
parent 04bf62b012
commit f01b3122e3
2 changed files with 49 additions and 32 deletions
+6 -4
View 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>
+43 -28
View 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: