summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-container.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-23 19:11:48 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-23 19:15:27 +0100
commitee502e0c28a611470a4e10b0c90bade6ff7fa389 (patch)
treeaaab86433eaf963b6615962534ccee5463390b77 /src/libsystemd/sd-bus/bus-container.c
parent080bfdbb8e9f3d23594b101d7f50e7e2f9e4699b (diff)
sd-bus: teach x-container-unix: bus protoocol to connect to the namespace of a PID instead of a container name
Diffstat (limited to 'src/libsystemd/sd-bus/bus-container.c')
-rw-r--r--src/libsystemd/sd-bus/bus-container.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c
index dd4bf1512e..d29b98a269 100644
--- a/src/libsystemd/sd-bus/bus-container.c
+++ b/src/libsystemd/sd-bus/bus-container.c
@@ -30,19 +30,22 @@
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, NULL, &rootfd);
+ r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
if (r < 0)
return r;
@@ -127,7 +130,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 +138,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, NULL, &rootfd);
+ r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
if (r < 0)
return r;