]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-bus/bus-container.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "bus-internal.h"
28 #include "bus-socket.h"
29 #include "bus-container.h"
31 int bus_container_connect(sd_bus
*b
) {
32 _cleanup_free_
char *s
= NULL
, *ns
= NULL
, *root
= NULL
, *class = NULL
;
33 _cleanup_close_
int nsfd
= -1, rootfd
= -1;
40 assert(b
->input_fd
< 0);
41 assert(b
->output_fd
< 0);
43 p
= strappenda("/run/systemd/machines/", b
->machine
);
44 r
= parse_env_file(p
, NEWLINE
, "LEADER", &s
, "CLASS", &class, NULL
);
52 if (!streq_ptr(class, "container"))
55 r
= parse_pid(s
, &leader
);
61 r
= asprintf(&ns
, "/proc/%lu/ns/mnt", (unsigned long) leader
);
65 nsfd
= open(ns
, O_RDONLY
|O_NOCTTY
|O_CLOEXEC
);
69 r
= asprintf(&root
, "/proc/%lu/root", (unsigned long) leader
);
73 rootfd
= open(root
, O_RDONLY
|O_NOCTTY
|O_CLOEXEC
|O_DIRECTORY
);
77 b
->input_fd
= socket(b
->sockaddr
.sa
.sa_family
, SOCK_STREAM
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, 0);
81 b
->output_fd
= b
->input_fd
;
83 r
= bus_socket_setup(b
);
92 r
= setns(nsfd
, CLONE_NEWNS
);
96 if (fchdir(rootfd
) < 0)
102 r
= connect(b
->input_fd
, &b
->sockaddr
.sa
, b
->sockaddr_size
);
104 if (errno
== EINPROGRESS
)
113 r
= wait_for_terminate(child
, &si
);
117 if (si
.si_code
!= CLD_EXITED
)
120 if (si
.si_status
== 1)
123 if (si
.si_status
!= 0)
126 return bus_socket_start_auth(b
);