nspawn: register a scope for the unit if --register=no is specified (#6166)

Previously, only when --register=yes was set (the default) the invoked
container would get its own scope, created by machined on behalf of
nspawn. With this change if --register=no is set nspawn will still get
its own scope (which is a good thing, so that --slice= and --property=
take effect), but this is not done through machined but by registering a
scope unit directly in PID 1.

Summary:

--register=yes             → allocate a new scope through machined (the default)
--register=yes --keep-unit → use the unit we are already running in an register with machined
--register=no              → allocate a new scope directly, but no machined
--register=no --keep-unit  → do not allocate nor register anything

Fixes: #5823
This commit is contained in:
Lennart Poettering
2017-06-28 13:22:46 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent 694859b5e7
commit cd2dfc6fae
4 changed files with 202 additions and 85 deletions
+15 -3
View File
@@ -1083,8 +1083,8 @@ static int parse_argv(int argc, char *argv[]) {
if (arg_userns_mode == USER_NAMESPACE_PICK)
arg_userns_chown = true;
if (arg_keep_unit && cg_pid_get_owner_uid(0, NULL) >= 0) {
log_error("--keep-unit may not be used when invoked from a user session.");
if (arg_keep_unit && arg_register && cg_pid_get_owner_uid(0, NULL) >= 0) {
log_error("--keep-unit --register=yes may not be used when invoked from a user session.");
return -EINVAL;
}
@@ -3387,7 +3387,19 @@ static int run(int master,
arg_container_service_name);
if (r < 0)
return r;
}
} else if (!arg_keep_unit) {
r = allocate_scope(
arg_machine,
*pid,
arg_slice,
arg_custom_mounts, arg_n_custom_mounts,
arg_kill_signal,
arg_property);
if (r < 0)
return r;
} else if (arg_slice || arg_property)
log_notice("Machine and scope registration turned off, --slice= and --property= settings will have no effect.");
r = sync_cgroup(*pid, arg_unified_cgroup_hierarchy, arg_uid_shift);
if (r < 0)