chiark / gitweb /
bus: stop using EDEADLOCK
[elogind.git] / src / libsystemd / sd-bus / bus-container.c
index 6bd7ad6318dd732c47b9e1ab684e4600e05344cf..3b3a5d357f755cd211da24ff44f8163bc703cc18 100644 (file)
 #include <fcntl.h>
 
 #include "util.h"
-#include "fileio.h"
 #include "bus-internal.h"
 #include "bus-socket.h"
 #include "bus-container.h"
 
 int bus_container_connect_socket(sd_bus *b) {
         _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
-        pid_t leader, child;
+        pid_t child;
         siginfo_t si;
         int r;
 
         assert(b);
         assert(b->input_fd < 0);
         assert(b->output_fd < 0);
+        assert(b->nspid > 0 || b->machine);
 
-        r = container_get_leader(b->machine, &leader);
-        if (r < 0)
-                return r;
+        if (b->nspid <= 0) {
+                r = container_get_leader(b->machine, &b->nspid);
+                if (r < 0)
+                        return r;
+        }
 
-        r = namespace_open(leader, &pidnsfd, &mntnsfd, &rootfd);
+        r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
         if (r < 0)
                 return r;
 
@@ -61,7 +63,7 @@ int bus_container_connect_socket(sd_bus *b) {
         if (child == 0) {
                 pid_t grandchild;
 
-                r = namespace_enter(pidnsfd, mntnsfd, rootfd);
+                r = namespace_enter(pidnsfd, mntnsfd, -1, rootfd);
                 if (r < 0)
                         _exit(255);
 
@@ -127,7 +129,7 @@ int bus_container_connect_kernel(sd_bus *b) {
                 .msg_controllen = sizeof(control),
         };
         struct cmsghdr *cmsg;
-        pid_t leader, child;
+        pid_t child;
         siginfo_t si;
         int r;
         _cleanup_close_ int fd = -1;
@@ -135,12 +137,15 @@ int bus_container_connect_kernel(sd_bus *b) {
         assert(b);
         assert(b->input_fd < 0);
         assert(b->output_fd < 0);
+        assert(b->nspid > 0 || b->machine);
 
-        r = container_get_leader(b->machine, &leader);
-        if (r < 0)
-                return r;
+        if (b->nspid <= 0) {
+                r = container_get_leader(b->machine, &b->nspid);
+                if (r < 0)
+                        return r;
+        }
 
-        r = namespace_open(leader, &pidnsfd, &mntnsfd, &rootfd);
+        r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
         if (r < 0)
                 return r;
 
@@ -156,7 +161,7 @@ int bus_container_connect_kernel(sd_bus *b) {
 
                 pair[0] = safe_close(pair[0]);
 
-                r = namespace_enter(pidnsfd, mntnsfd, rootfd);
+                r = namespace_enter(pidnsfd, mntnsfd, -1, rootfd);
                 if (r < 0)
                         _exit(EXIT_FAILURE);