]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homectl: split out helper parse_auto_resize_mode_field
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 10 Dec 2025 14:33:41 +0000 (15:33 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Jan 2026 16:59:54 +0000 (17:59 +0100)
src/home/homectl.c

index 66da4de34e58d249a21333f7a3b1d8c42473c54e..aa6bbec1458fba335b74093c93ec129f7c88f8c2 100644 (file)
@@ -3357,6 +3357,22 @@ static int parse_nice_field(sd_json_variant **identity, const char *field, const
         return 0;
 }
 
+static int parse_auto_resize_mode_field(sd_json_variant **identity, const char *field, const char *arg) {
+        int r;
+
+        assert(identity);
+        assert(field);
+
+        if (!isempty(arg)) {
+                r = auto_resize_mode_from_string(arg);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse %s parameter: %s", field, arg);
+                arg = auto_resize_mode_to_string(r);
+        }
+
+        return parse_string_field(identity, field, arg);
+}
+
 static int parse_rlimit_field(sd_json_variant **identity, const char *field, const char *arg) {
         int r;
 
@@ -4614,22 +4630,10 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_AUTO_RESIZE_MODE:
-                        if (isempty(optarg)) {
-                                r = drop_from_identity("autoResizeMode");
-                                if (r < 0)
-                                        return r;
-
-                                break;
-                        }
-
-                        r = auto_resize_mode_from_string(optarg);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to parse --auto-resize-mode= argument: %s", optarg);
-
-                        r = sd_json_variant_set_field_string(match_identity ?: &arg_identity_extra, "autoResizeMode", auto_resize_mode_to_string(r));
+                        r = parse_auto_resize_mode_field(match_identity ?: &arg_identity_extra,
+                                                         "autoResizeMode", optarg);
                         if (r < 0)
-                                return log_error_errno(r, "Failed to set autoResizeMode field: %m");
-
+                                return r;
                         break;
 
                 case ARG_REBALANCE_WEIGHT: {