]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: allow connecting to the pseudo-container ".host"
authorLennart Poettering <lennart@poettering.net>
Tue, 17 Jul 2018 10:23:26 +0000 (12:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 25 Jul 2018 20:48:11 +0000 (22:48 +0200)
machined exposes the pseudo-container ".host" as a reference to the host
system, and this means "machinectl login .host" and "machinectl shell
.host" get your a login/shell on the host. systemd-run currently doesn't
allow that. Let's fix that, and make sd-bus understand ".host" as an
alias for connecting to the host system.

src/basic/util.c
src/libsystemd/sd-bus/sd-bus.c

index 2206c1b4ad124e9d891a2dee0c83878b9efff95b..f951d641d70dc9eccc785d6e15df8cb1f2824e91 100644 (file)
@@ -230,6 +230,11 @@ int container_get_leader(const char *machine, pid_t *pid) {
         assert(machine);
         assert(pid);
 
+        if (streq(machine, ".host")) {
+                *pid = 1;
+                return 0;
+        }
+
         if (!machine_name_is_valid(machine))
                 return -EINVAL;
 
index a87f4625ecaf2ebe7c617b3ba8502572529b7374..4412fe152fdf7c2e270463239b91ebf49d37e380 100644 (file)
@@ -949,7 +949,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
                 return -EINVAL;
 
         if (machine) {
-                if (!machine_name_is_valid(machine))
+                if (!streq(machine, ".host") && !machine_name_is_valid(machine))
                         return -EINVAL;
 
                 free_and_replace(b->machine, machine);
@@ -1447,7 +1447,7 @@ _public_ int sd_bus_open_system_machine(sd_bus **ret, const char *machine) {
 
         assert_return(machine, -EINVAL);
         assert_return(ret, -EINVAL);
-        assert_return(machine_name_is_valid(machine), -EINVAL);
+        assert_return(streq(machine, ".host") || machine_name_is_valid(machine), -EINVAL);
 
         r = sd_bus_new(&b);
         if (r < 0)