summaryrefslogtreecommitdiff
path: root/src/nspawn
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-09-27 14:51:53 +0200
committerFilipe Brandenburger <filbranden@gmail.com>2019-10-01 10:21:13 -0700
commit75b0d8b89d6e86319e75eaead3f4b0d187a66729 (patch)
treec58bd3176cf7a3a62b2818091c8208fbcd6e2855 /src/nspawn
parent2805536bff6de4001255a3f93b558a1242df0114 (diff)
downloadsystemd-75b0d8b89d6e86319e75eaead3f4b0d187a66729.tar.gz
systemd-75b0d8b89d6e86319e75eaead3f4b0d187a66729.tar.bz2
systemd-75b0d8b89d6e86319e75eaead3f4b0d187a66729.zip
nspawn: default to unified hierarchy if --as-pid2 is used
See comment added in the patch. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1756143.
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 2aec8041f0..ff6983eb7a 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -433,8 +433,8 @@ static int detect_unified_cgroup_hierarchy_from_environment(void) {
static int detect_unified_cgroup_hierarchy_from_image(const char *directory) {
int r;
- /* Let's inherit the mode to use from the host system, but let's take into consideration what systemd in the
- * image actually supports. */
+ /* Let's inherit the mode to use from the host system, but let's take into consideration what systemd
+ * in the image actually supports. */
r = cg_all_unified();
if (r < 0)
return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
@@ -1440,6 +1440,25 @@ static int parse_argv(int argc, char *argv[]) {
static int verify_arguments(void) {
int r;
+ if (arg_start_mode == START_PID2 && arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_UNKNOWN) {
+ /* If we are running the stub init in the container, we don't need to look at what the init
+ * in the container supports, because we are not using it. Let's immediately pick the right
+ * setting based on the host system configuration.
+ *
+ * We only do this, if the user didn't use an environment variable to override the detection.
+ */
+
+ r = cg_all_unified();
+ if (r < 0)
+ return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
+ if (r > 0)
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
+ else if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0)
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD;
+ else
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
+ }
+
if (arg_userns_mode != USER_NAMESPACE_NO)
arg_mount_settings |= MOUNT_USE_USERNS;