teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0195-sd-bus-allow-connecting-to-the-pseudo-container-.hos.patch

4bff0a
From 6bf178a9a6e3fd6544d8e37a0082febf81c0ad2d Mon Sep 17 00:00:00 2001
4bff0a
From: Lennart Poettering <lennart@poettering.net>
4bff0a
Date: Tue, 17 Jul 2018 12:23:26 +0200
4bff0a
Subject: [PATCH] sd-bus: allow connecting to the pseudo-container ".host"
4bff0a
4bff0a
machined exposes the pseudo-container ".host" as a reference to the host
4bff0a
system, and this means "machinectl login .host" and "machinectl shell
4bff0a
.host" get your a login/shell on the host. systemd-run currently doesn't
4bff0a
allow that. Let's fix that, and make sd-bus understand ".host" as an
4bff0a
alias for connecting to the host system.
4bff0a
4bff0a
(cherry picked from commit 1e5057b904473696ae0d591d7555233adcb51fa4)
4bff0a
4bff0a
Resolves: #1683334
4bff0a
---
4bff0a
 src/basic/util.c               | 5 +++++
4bff0a
 src/libsystemd/sd-bus/sd-bus.c | 4 ++--
4bff0a
 2 files changed, 7 insertions(+), 2 deletions(-)
4bff0a
4bff0a
diff --git a/src/basic/util.c b/src/basic/util.c
4bff0a
index 8f2d6061da..82cb937314 100644
4bff0a
--- a/src/basic/util.c
4bff0a
+++ b/src/basic/util.c
4bff0a
@@ -255,6 +255,11 @@ int container_get_leader(const char *machine, pid_t *pid) {
4bff0a
         assert(machine);
4bff0a
         assert(pid);
4bff0a
 
4bff0a
+        if (streq(machine, ".host")) {
4bff0a
+                *pid = 1;
4bff0a
+                return 0;
4bff0a
+        }
4bff0a
+
4bff0a
         if (!machine_name_is_valid(machine))
4bff0a
                 return -EINVAL;
4bff0a
 
4bff0a
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
4bff0a
index 7f03528b89..f53a98d6bf 100644
4bff0a
--- a/src/libsystemd/sd-bus/sd-bus.c
4bff0a
+++ b/src/libsystemd/sd-bus/sd-bus.c
4bff0a
@@ -952,7 +952,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
4bff0a
                 return -EINVAL;
4bff0a
 
4bff0a
         if (machine) {
4bff0a
-                if (!machine_name_is_valid(machine))
4bff0a
+                if (!streq(machine, ".host") && !machine_name_is_valid(machine))
4bff0a
                         return -EINVAL;
4bff0a
 
4bff0a
                 free_and_replace(b->machine, machine);
4bff0a
@@ -1450,7 +1450,7 @@ _public_ int sd_bus_open_system_machine(sd_bus **ret, const char *machine) {
4bff0a
 
4bff0a
         assert_return(machine, -EINVAL);
4bff0a
         assert_return(ret, -EINVAL);
4bff0a
-        assert_return(machine_name_is_valid(machine), -EINVAL);
4bff0a
+        assert_return(streq(machine, ".host") || machine_name_is_valid(machine), -EINVAL);
4bff0a
 
4bff0a
         r = sd_bus_new(&b);
4bff0a
         if (r < 0)