diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-05 22:54:57 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-11-09 17:08:59 +0100 |
commit | 11d81e506ed68c6c5cebe319dc57a9a2fc4319c5 (patch) | |
tree | b6d79b20bc5579c6c8922e8af3c62df376c1e13a /src/nspawn/nspawn-register.c | |
parent | nspawn: make use of the new sd_bus_set_close_on_exit() call in nspawn (diff) | |
download | systemd-11d81e506ed68c6c5cebe319dc57a9a2fc4319c5.tar.xz systemd-11d81e506ed68c6c5cebe319dc57a9a2fc4319c5.zip |
nspawn: simplify machine terminate bus call
We have the machine name anyway, let's use TerminateMachine() on
machined's Manager object directly with it. That way it's a single
method call only, instead of two, to terminate the machine.
Diffstat (limited to 'src/nspawn/nspawn-register.c')
-rw-r--r-- | src/nspawn/nspawn-register.c | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c index 85f3cf1c01..e459cb63ec 100644 --- a/src/nspawn/nspawn-register.c +++ b/src/nspawn/nspawn-register.c @@ -201,10 +201,11 @@ int register_machine( return 0; } -int terminate_machine(sd_bus *bus, pid_t pid) { +int terminate_machine( + sd_bus *bus, + const char *machine_name) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; - const char *path; int r; assert(bus); @@ -214,32 +215,11 @@ int terminate_machine(sd_bus *bus, pid_t pid) { "org.freedesktop.machine1", "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", - "GetMachineByPID", - &error, - &reply, - "u", - (uint32_t) pid); - if (r < 0) { - /* Note that the machine might already have been - * cleaned up automatically, hence don't consider it a - * failure if we cannot get the machine object. */ - log_debug("Failed to get machine: %s", bus_error_message(&error, r)); - return 0; - } - - r = sd_bus_message_read(reply, "o", &path); - if (r < 0) - return bus_log_parse_error(r); - - r = sd_bus_call_method( - bus, - "org.freedesktop.machine1", - path, - "org.freedesktop.machine1.Machine", - "Terminate", + "TerminateMachine", &error, NULL, - NULL); + "s", + machine_name); if (r < 0) log_debug("Failed to terminate machine: %s", bus_error_message(&error, r)); |