]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machined: also take new ProcessId structure when registering processes 34703/head
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Oct 2024 20:03:51 +0000 (22:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Oct 2024 08:48:07 +0000 (10:48 +0200)
src/machine/machine-varlink.c
src/shared/varlink-io.systemd.Machine.c

index 26b1e841a6009ab292f584b5e70607fb5f75f209..a1ecdffa910d9a15f407ef3f967107a3982f20e8 100644 (file)
@@ -45,25 +45,16 @@ static int machine_name(const char *name, sd_json_variant *variant, sd_json_disp
 static int machine_leader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
         PidRef *leader = ASSERT_PTR(userdata);
         _cleanup_(pidref_done) PidRef temp = PIDREF_NULL;
-        uint64_t k;
         int r;
 
-        if (!sd_json_variant_is_unsigned(variant))
-                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
-
-        k = sd_json_variant_unsigned(variant);
-        if (k > PID_T_MAX || !pid_is_valid(k))
-                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid PID.", strna(name));
+        r = json_dispatch_pidref(name, variant, flags, &temp);
+        if (r < 0)
+                return r;
 
-        if (k == 1)
+        if (temp.pid == 1) /* refuse PID 1 */
                 return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid leader PID.", strna(name));
 
-        r = pidref_set_pid(&temp, k);
-        if (r < 0)
-                return json_log(variant, flags, r, "Failed to pin process " PID_FMT ": %m", leader->pid);
-
         pidref_done(leader);
-
         *leader = TAKE_PIDREF(temp);
 
         return 0;
@@ -133,7 +124,7 @@ int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink
                 { "id",                SD_JSON_VARIANT_STRING,        sd_json_dispatch_id128,   offsetof(Machine, id),                   0                 },
                 { "service",           SD_JSON_VARIANT_STRING,        sd_json_dispatch_string,  offsetof(Machine, service),              0                 },
                 { "class",             SD_JSON_VARIANT_STRING,        dispatch_machine_class,   offsetof(Machine, class),                SD_JSON_MANDATORY },
-                { "leader",            SD_JSON_VARIANT_UNSIGNED,      machine_leader,           offsetof(Machine, leader),               0                 },
+                { "leader",            _SD_JSON_VARIANT_TYPE_INVALID, machine_leader,           offsetof(Machine, leader),               SD_JSON_STRICT    },
                 { "rootDirectory",     SD_JSON_VARIANT_STRING,        json_dispatch_path,       offsetof(Machine, root_directory),       0                 },
                 { "ifIndices",         SD_JSON_VARIANT_ARRAY,         machine_ifindices,        0,                                       0                 },
                 { "vSockCid",          _SD_JSON_VARIANT_TYPE_INVALID, machine_cid,              offsetof(Machine, vsock_cid),            0                 },
index 332f50e588ae15ad01c0d9fa448a73e4e975d890..ce802491236c6c098263dac3bcc00f71b2aa1aba 100644 (file)
@@ -12,7 +12,7 @@ static SD_VARLINK_DEFINE_METHOD(
                 SD_VARLINK_DEFINE_INPUT(id,                SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 SD_VARLINK_DEFINE_INPUT(service,           SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 SD_VARLINK_DEFINE_INPUT(class,             SD_VARLINK_STRING, 0),
-                SD_VARLINK_DEFINE_INPUT(leader,            SD_VARLINK_INT,    SD_VARLINK_NULLABLE),
+                SD_VARLINK_DEFINE_INPUT_BY_TYPE(leader,    ProcessId,         SD_VARLINK_NULLABLE),
                 SD_VARLINK_DEFINE_INPUT(rootDirectory,     SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 SD_VARLINK_DEFINE_INPUT(ifIndices,         SD_VARLINK_INT,    SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE),
                 SD_VARLINK_DEFINE_INPUT(vSockCid,          SD_VARLINK_INT,    SD_VARLINK_NULLABLE),