summaryrefslogtreecommitdiff
path: root/src/nspawn/nspawn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nspawn/nspawn.c')
-rw-r--r--src/nspawn/nspawn.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index c0b4c3142d..be1b054045 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -320,13 +320,8 @@ static int custom_mounts_prepare(void) {
return 0;
}
-static int pick_cgroup_version(const char *directory) {
+static int pick_cgroup_version(const char *directory, CGroupUnified outer) {
int r;
- CGroupUnified outer;
-
- r = cg_version(&outer);
- if (r < 0)
- return log_error_errno(r, "Failed to determine whether the unified cgroups hierarchy is used: %m");
/* Otherwise inherit the default from the host system, unless
* the container doesn't have a new enough systemd (detected
@@ -2652,7 +2647,8 @@ static int inner_child(
bool secondary,
int kmsg_socket,
int rtnl_socket,
- FDSet *fds) {
+ FDSet *fds,
+ CGroupUnified outer_cgver) {
_cleanup_free_ char *home = NULL;
char as_uuid[37];
@@ -2719,6 +2715,7 @@ static int inner_child(
return log_error_errno(errno, "Failed to unshare cgroup namespace");
r = mount_cgroups(
"",
+ outer_cgver,
arg_unified_cgroup_hierarchy,
arg_userns_mode != USER_NAMESPACE_NO,
arg_uid_shift,
@@ -2925,7 +2922,8 @@ static int outer_child(
int kmsg_socket,
int rtnl_socket,
int uid_shift_socket,
- FDSet *fds) {
+ FDSet *fds,
+ CGroupUnified outer_cgver) {
pid_t pid;
ssize_t l;
@@ -3122,6 +3120,7 @@ static int outer_child(
if (!arg_use_cgns) {
r = mount_cgroups(
directory,
+ outer_cgver,
arg_unified_cgroup_hierarchy,
arg_userns_mode != USER_NAMESPACE_NO,
arg_uid_shift,
@@ -3156,7 +3155,7 @@ static int outer_child(
* requested, so that we all are owned by the user if
* user namespaces are turned on. */
- r = inner_child(barrier, directory, secondary, kmsg_socket, rtnl_socket, fds);
+ r = inner_child(barrier, directory, secondary, kmsg_socket, rtnl_socket, fds, outer_cgver);
if (r < 0)
_exit(EXIT_FAILURE);
@@ -3599,6 +3598,7 @@ static int run(int master,
const char *esp_device,
bool interactive,
bool secondary,
+ CGroupUnified outer_cgver,
FDSet *fds,
char veth_name[IFNAMSIZ], bool *veth_created,
union in_addr_union *exposed,
@@ -3715,7 +3715,8 @@ static int run(int master,
kmsg_socket_pair[1],
rtnl_socket_pair[1],
uid_shift_socket_pair[1],
- fds);
+ fds,
+ outer_cgver);
if (r < 0)
_exit(EXIT_FAILURE);
@@ -3874,12 +3875,12 @@ static int run(int master,
return r;
}
- r = sync_cgroup(*pid, arg_unified_cgroup_hierarchy, arg_uid_shift);
+ r = sync_cgroup(*pid, outer_cgver, arg_unified_cgroup_hierarchy, arg_uid_shift);
if (r < 0)
return r;
if (arg_keep_unit) {
- r = create_subcgroup(*pid, arg_unified_cgroup_hierarchy);
+ r = create_subcgroup(*pid, outer_cgver, arg_unified_cgroup_hierarchy);
if (r < 0)
return r;
}
@@ -4025,6 +4026,7 @@ int main(int argc, char *argv[]) {
union in_addr_union exposed = {};
_cleanup_release_lock_file_ LockFile tree_global_lock = LOCK_FILE_INIT, tree_local_lock = LOCK_FILE_INIT;
bool interactive, veth_created = false;
+ CGroupUnified outer_cgver;
log_parse_environment();
log_open();
@@ -4043,6 +4045,13 @@ int main(int argc, char *argv[]) {
r = -EPERM;
goto finish;
}
+
+ r = cg_version(&outer_cgver);
+ if (r < 0) {
+ log_error_errno(r, "Failed to determine whether the unified cgroups hierarchy is used: %m");
+ goto finish;
+ }
+
r = determine_names();
if (r < 0)
goto finish;
@@ -4206,7 +4215,7 @@ int main(int argc, char *argv[]) {
goto finish;
if (arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_UNKNOWN) {
- r = pick_cgroup_version(arg_directory);
+ r = pick_cgroup_version(arg_directory, outer_cgver);
if (r < 0)
goto finish;
}
@@ -4257,6 +4266,7 @@ int main(int argc, char *argv[]) {
srv_device, srv_device_rw,
esp_device,
interactive, secondary,
+ outer_cgver,
fds,
veth_name, &veth_created,
&exposed,