chiark / gitweb /
fsck: unify exit path for connect_plymouth()
[elogind.git] / src / machine / machine-dbus.c
index 405c072b90120a64a9eb0e80df7c0b3aea26b7dd..d6b8c90090fedeec14bcc0b2523f4d1265aa08b6 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <errno.h>
 #include <string.h>
-#include <arpa/inet.h>
 #include <sys/mount.h>
 
 /* When we include libgen.h because we need dirname() we immediately
@@ -133,6 +132,7 @@ int bus_machine_method_terminate(sd_bus *bus, sd_bus_message *message, void *use
                         CAP_KILL,
                         "org.freedesktop.machine1.manage-machines",
                         false,
+                        UID_INVALID,
                         &m->manager->polkit_registry,
                         error);
         if (r < 0)
@@ -178,6 +178,7 @@ int bus_machine_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata
                         CAP_KILL,
                         "org.freedesktop.machine1.manage-machines",
                         false,
+                        UID_INVALID,
                         &m->manager->polkit_registry,
                         error);
         if (r < 0)
@@ -470,6 +471,7 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
         _cleanup_close_ int master = -1;
         Machine *m = userdata;
         const char *p;
+        char *address;
         int r;
 
         if (m->class != MACHINE_CONTAINER)
@@ -480,6 +482,7 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
                         CAP_SYS_ADMIN,
                         "org.freedesktop.machine1.login",
                         false,
+                        UID_INVALID,
                         &m->manager->polkit_registry,
                         error);
         if (r < 0)
@@ -507,13 +510,14 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
                 return r;
 
 #ifdef ENABLE_KDBUS
-        asprintf(&container_bus->address, "x-machine-kernel:pid=" PID_FMT ";x-machine-unix:pid=" PID_FMT, m->leader, m->leader);
+#  define ADDRESS_FMT "x-machine-kernel:pid=%1$" PID_PRI ";x-machine-unix:pid=%1$" PID_PRI
 #else
-        asprintf(&container_bus->address, "x-machine-kernel:pid=" PID_FMT, m->leader);
+#  define ADDRESS_FMT "x-machine-unix:pid=%1$" PID_PRI
 #endif
-        if (!container_bus->address)
+        if (asprintf(&address, ADDRESS_FMT, m->leader) < 0)
                 return log_oom();
 
+        container_bus->address = address;
         container_bus->bus_client = true;
         container_bus->trusted = false;
         container_bus->is_system = true;
@@ -583,6 +587,7 @@ int bus_machine_method_bind_mount(sd_bus *bus, sd_bus_message *message, void *us
                         CAP_SYS_ADMIN,
                         "org.freedesktop.machine1.manage-machines",
                         false,
+                        UID_INVALID,
                         &m->manager->polkit_registry,
                         error);
         if (r < 0)
@@ -841,6 +846,7 @@ int bus_machine_method_copy(sd_bus *bus, sd_bus_message *message, void *userdata
                         CAP_SYS_ADMIN,
                         "org.freedesktop.machine1.manage-machines",
                         false,
+                        UID_INVALID,
                         &m->manager->polkit_registry,
                         error);
         if (r < 0)
@@ -867,7 +873,7 @@ int bus_machine_method_copy(sd_bus *bus, sd_bus_message *message, void *userdata
         container_dirname = dirname(t);
 
         hostfd = open(host_dirname, O_CLOEXEC|O_RDONLY|O_NOCTTY|O_DIRECTORY);
-        if (r < 0)
+        if (hostfd < 0)
                 return sd_bus_error_set_errnof(error, errno, "Failed to open host directory %s: %m", host_dirname);
 
         if (pipe2(errno_pipe_fd, O_CLOEXEC|O_NONBLOCK) < 0)