]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: split out helper for --property=
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 13 May 2026 15:10:00 +0000 (17:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 14 May 2026 07:03:11 +0000 (09:03 +0200)
We explicitly handled --property= in a specific way, so preserve
that behaviour.

src/systemctl/systemctl.c

index 47f34e1ad3434e084e9775701f86fa0f35cf3204..00da6d39b498c2f3628e117bb1028d504377946f 100644 (file)
@@ -327,6 +327,34 @@ static int systemctl_help(void) {
         return 0;
 }
 
+static int parse_property_argument(const char *value, char ***properties) {
+        int r;
+
+        assert(value);
+        assert(properties);
+
+        if (isempty(value) && !*properties) {
+                /* Make sure that if the empty property list was specified, we won't show any properties. */
+                *properties = strv_new(NULL);
+                if (!*properties)
+                        return log_oom();
+        } else
+                for (const char *p = value;;) {
+                        _cleanup_free_ char *prop = NULL;
+
+                        r = extract_first_word(&p, &prop, ",", /* flags= */ 0);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse property: '%s'", value);
+                        if (r == 0)
+                                break;
+
+                        if (strv_consume(properties, TAKE_PTR(prop)) < 0)
+                                return log_oom();
+                }
+
+        return 0;
+}
+
 static void help_types(void) {
         if (arg_legend != 0)
                 puts("Available unit types:");
@@ -613,25 +641,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         _fallthrough_;
 
                 case 'p':
-                        /* Make sure that if the empty property list was specified, we won't show any
-                           properties. */
-                        if (isempty(optarg) && !arg_properties) {
-                                arg_properties = new0(char*, 1);
-                                if (!arg_properties)
-                                        return log_oom();
-                        } else
-                                for (const char *p = optarg;;) {
-                                        _cleanup_free_ char *prop = NULL;
-
-                                        r = extract_first_word(&p, &prop, ",", 0);
-                                        if (r < 0)
-                                                return log_error_errno(r, "Failed to parse property: %s", optarg);
-                                        if (r == 0)
-                                                break;
-
-                                        if (strv_consume(&arg_properties, TAKE_PTR(prop)) < 0)
-                                                return log_oom();
-                                }
+                        r = parse_property_argument(optarg, &arg_properties);
+                        if (r < 0)
+                                return r;
 
                         /* If the user asked for a particular property, show it, even if it is empty. */
                         SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);