diff options
author | Ivan Kruglov <mail@ikruglov.com> | 2024-10-10 11:51:57 +0200 |
---|---|---|
committer | Ivan Kruglov <mail@ikruglov.com> | 2024-10-10 13:40:45 +0200 |
commit | f6cb4d4afb1c88551088b00724140f80d1368f73 (patch) | |
tree | f3d36bdade41a97fddcb3a2e09b4eb7eed509170 /src/machine/machined-dbus.c | |
parent | machine: use sd_json_dispatch_signal() in varlink code (diff) | |
download | systemd-f6cb4d4afb1c88551088b00724140f80d1368f73.tar.xz systemd-f6cb4d4afb1c88551088b00724140f80d1368f73.zip |
machine: switch to use PidRef when lookup machine by pid in dbus and varlink interfaces
This commit includes adding introduce manager_get_machine_by_pidref() as a replacement for manager_get_machine_by_pid()
and moving surrounding code to utilise PidRef.
Diffstat (limited to 'src/machine/machined-dbus.c')
-rw-r--r-- | src/machine/machined-dbus.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index e86be6d4d5..730b436545 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -137,6 +137,7 @@ static int method_get_image(sd_bus_message *message, void *userdata, sd_bus_erro } static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { + _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; _cleanup_free_ char *p = NULL; Manager *m = ASSERT_PTR(userdata); Machine *machine = NULL; @@ -154,19 +155,21 @@ static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd if (pid < 0) return -EINVAL; + pidref = PIDREF_MAKE_FROM_PID(pid); + if (pid == 0) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; - r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_PIDFD, &creds); if (r < 0) return r; - r = sd_bus_creds_get_pid(creds, &pid); + r = bus_creds_get_pidref(creds, &pidref); if (r < 0) return r; } - r = manager_get_machine_by_pid(m, pid, &machine); + r = manager_get_machine_by_pidref(m, &pidref, &machine); if (r < 0) return r; if (r == 0) |