Blame SOURCES/0113-nspawn-simplify-machine-terminate-bus-call.patch

a3e2b5
From 74640adc3e79064ab34f7ced59e231603c58f07c Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Fri, 5 Oct 2018 22:54:57 +0200
a3e2b5
Subject: [PATCH] nspawn: simplify machine terminate bus call
a3e2b5
a3e2b5
We have the machine name anyway, let's use TerminateMachine() on
a3e2b5
machined's Manager object directly with it. That way it's a single
a3e2b5
method call only, instead of two, to terminate the machine.
a3e2b5
a3e2b5
(cherry picked from commit 11d81e506ed68c6c5cebe319dc57a9a2fc4319c5)
a3e2b5
a3e2b5
Resolves: #1697893
a3e2b5
---
a3e2b5
 src/nspawn/nspawn-register.c | 34 +++++++---------------------------
a3e2b5
 src/nspawn/nspawn-register.h |  2 +-
a3e2b5
 src/nspawn/nspawn.c          |  2 +-
a3e2b5
 3 files changed, 9 insertions(+), 29 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c
a3e2b5
index 85f3cf1c01..e459cb63ec 100644
a3e2b5
--- a/src/nspawn/nspawn-register.c
a3e2b5
+++ b/src/nspawn/nspawn-register.c
a3e2b5
@@ -201,10 +201,11 @@ int register_machine(
a3e2b5
         return 0;
a3e2b5
 }
a3e2b5
 
a3e2b5
-int terminate_machine(sd_bus *bus, pid_t pid) {
a3e2b5
+int terminate_machine(
a3e2b5
+                sd_bus *bus,
a3e2b5
+                const char *machine_name) {
a3e2b5
+
a3e2b5
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
a3e2b5
-        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
a3e2b5
-        const char *path;
a3e2b5
         int r;
a3e2b5
 
a3e2b5
         assert(bus);
a3e2b5
@@ -214,32 +215,11 @@ int terminate_machine(sd_bus *bus, pid_t pid) {
a3e2b5
                         "org.freedesktop.machine1",
a3e2b5
                         "/org/freedesktop/machine1",
a3e2b5
                         "org.freedesktop.machine1.Manager",
a3e2b5
-                        "GetMachineByPID",
a3e2b5
-                        &error,
a3e2b5
-                        &reply,
a3e2b5
-                        "u",
a3e2b5
-                        (uint32_t) pid);
a3e2b5
-        if (r < 0) {
a3e2b5
-                /* Note that the machine might already have been
a3e2b5
-                 * cleaned up automatically, hence don't consider it a
a3e2b5
-                 * failure if we cannot get the machine object. */
a3e2b5
-                log_debug("Failed to get machine: %s", bus_error_message(&error, r));
a3e2b5
-                return 0;
a3e2b5
-        }
a3e2b5
-
a3e2b5
-        r = sd_bus_message_read(reply, "o", &path);
a3e2b5
-        if (r < 0)
a3e2b5
-                return bus_log_parse_error(r);
a3e2b5
-
a3e2b5
-        r = sd_bus_call_method(
a3e2b5
-                        bus,
a3e2b5
-                        "org.freedesktop.machine1",
a3e2b5
-                        path,
a3e2b5
-                        "org.freedesktop.machine1.Machine",
a3e2b5
-                        "Terminate",
a3e2b5
+                        "TerminateMachine",
a3e2b5
                         &error,
a3e2b5
                         NULL,
a3e2b5
-                        NULL);
a3e2b5
+                        "s",
a3e2b5
+                        machine_name);
a3e2b5
         if (r < 0)
a3e2b5
                 log_debug("Failed to terminate machine: %s", bus_error_message(&error, r));
a3e2b5
 
a3e2b5
diff --git a/src/nspawn/nspawn-register.h b/src/nspawn/nspawn-register.h
a3e2b5
index 30807b9687..ddd8b053a3 100644
a3e2b5
--- a/src/nspawn/nspawn-register.h
a3e2b5
+++ b/src/nspawn/nspawn-register.h
a3e2b5
@@ -8,6 +8,6 @@
a3e2b5
 #include "nspawn-mount.h"
a3e2b5
 
a3e2b5
 int register_machine(sd_bus *bus, const char *machine_name, pid_t pid, const char *directory, sd_id128_t uuid, int local_ifindex, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties, bool keep_unit, const char *service);
a3e2b5
-int terminate_machine(sd_bus *bus, pid_t pid);
a3e2b5
+int terminate_machine(sd_bus *bus, const char *machine_name);
a3e2b5
 
a3e2b5
 int allocate_scope(sd_bus *bus, const char *machine_name, pid_t pid, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties);
a3e2b5
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
a3e2b5
index 8aec893a69..c4943f6eb7 100644
a3e2b5
--- a/src/nspawn/nspawn.c
a3e2b5
+++ b/src/nspawn/nspawn.c
a3e2b5
@@ -4066,7 +4066,7 @@ static int run(int master,
a3e2b5
 
a3e2b5
         /* Kill if it is not dead yet anyway */
a3e2b5
         if (arg_register && !arg_keep_unit && bus)
a3e2b5
-                terminate_machine(bus, *pid);
a3e2b5
+                terminate_machine(bus, arg_machine);
a3e2b5
 
a3e2b5
         /* Normally redundant, but better safe than sorry */
a3e2b5
         (void) kill(*pid, SIGKILL);