From 489fae526d6d8625ee7c4dd9221f1474518684de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 11 Dec 2018 12:00:06 +0100 Subject: [PATCH] nspawn: check cg_ns_supported() just once cg_ns_supported() caches, so the condition was really checked just once, but it looks weird to assign the return value to arg_use_cgns (if the variable is not present), because then the other checks are effectively equivalent to if (cg_ns_supported() && cg_ns_supported()) { ... and later if (!cg_ns_supported() || !cg_ns_supported()) { ... --- src/nspawn/nspawn.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index f4f7c1fd1f..91c97b60a7 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -442,11 +442,11 @@ static void parse_environment(void) { parse_mount_settings_env(); + /* SYSTEMD_NSPAWN_USE_CGNS=0 can be used to disable CLONE_NEWCGROUP use, + * even if it is supported. If not supported, it has no effect. */ r = getenv_bool("SYSTEMD_NSPAWN_USE_CGNS"); - if (r < 0) - arg_use_cgns = cg_ns_supported(); - else - arg_use_cgns = r; + if (r == 0 || !cg_ns_supported()) + arg_use_cgns = false; e = getenv("SYSTEMD_NSPAWN_CONTAINER_SERVICE"); if (e) @@ -2567,7 +2567,7 @@ static int inner_child( return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Parent died too early"); - if (arg_use_cgns && cg_ns_supported()) { + if (arg_use_cgns) { r = unshare(CLONE_NEWCGROUP); if (r < 0) return log_error_errno(errno, "Failed to unshare cgroup namespace: %m"); @@ -3037,7 +3037,7 @@ static int outer_child( if (r < 0) return r; - if (!arg_use_cgns || !cg_ns_supported()) { + if (!arg_use_cgns) { r = mount_cgroups( directory, arg_unified_cgroup_hierarchy,