]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: define helper for CPUAffinity=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Jun 2025 12:07:50 +0000 (14:07 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 17:35:12 +0000 (19:35 +0200)
src/shared/bus-unit-util.c

index 4ad3e49e44dbcf32644b5e9266ef6fbdf535e74a..e88fa24f4306b7b8988b95298bdd1a97d27f1edb 100644 (file)
@@ -1315,6 +1315,19 @@ static int bus_append_capabilities(sd_bus_message *m, const char *field, const c
         return 1;
 }
 
+static int bus_append_cpu_affinity(sd_bus_message *m, const char *field, const char *eq) {
+        int r;
+
+        if (streq_ptr(eq, "numa")) {
+                r = sd_bus_message_append(m, "(sv)", "CPUAffinityFromNUMA", "b", true);
+                if (r < 0)
+                        return bus_log_create_error(r);
+                return r;
+        }
+
+        return bus_append_parse_cpu_set(m, field, eq);
+}
+
 static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
         if (STR_IN_SET(field, "DevicePolicy",
                               "Slice",
@@ -1634,28 +1647,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
                               "AmbientCapabilities"))
                 return bus_append_capabilities(m, field, eq);
 
-        if (streq(field, "CPUAffinity")) {
-                _cleanup_(cpu_set_done) CPUSet cpuset = {};
-                _cleanup_free_ uint8_t *array = NULL;
-                size_t allocated;
-
-                if (eq && streq(eq, "numa")) {
-                        r = sd_bus_message_append(m, "(sv)", "CPUAffinityFromNUMA", "b", true);
-                        if (r < 0)
-                                return bus_log_create_error(r);
-                        return r;
-                }
-
-                r = parse_cpu_set(eq, &cpuset);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
-
-                r = cpu_set_to_dbus(&cpuset, &array, &allocated);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to serialize CPUAffinity: %m");
-
-                return bus_append_byte_array(m, field, array, allocated);
-        }
+        if (streq(field, "CPUAffinity"))
+                return bus_append_cpu_affinity(m, field, eq);
 
         if (streq(field, "NUMAPolicy")) {
                 r = mpol_from_string(eq);