From: Zbigniew Jędrzejewski-Szmek Date: Wed, 13 May 2026 15:32:44 +0000 (+0200) Subject: systemctl: split out helper for --what and allow resetting X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f01b3122e33f56b0e5d871d6e81a0a6711b9312b;p=thirdparty%2Fsystemd.git systemctl: split out helper for --what and allow resetting Analogous to parent commit. --- diff --git a/man/systemctl.xml b/man/systemctl.xml index a6d295927ae..ce485aee14f 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -2578,10 +2578,12 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err all as a shortcut for specifying all six resource types. If this option is not specified defaults to the combination of cache, runtime and fdstore, 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 - fdstore resource type is only useful if the - FileDescriptorStorePreserve= option is enabled, since the file descriptor store - is otherwise cleaned automatically when the unit is stopped. + to be redundant and can be reconstructed on next invocation. The empty argument can be used to + reset to this default. + + Note that the explicit removal of the fdstore resource type is only + useful if the FileDescriptorStorePreserve= option is enabled, since the file + descriptor store is otherwise cleaned automatically when the unit is stopped. diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 5c90092f2af..632e54256cb 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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: