1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00

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()) { ...
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-12-11 12:00:06 +01:00 committed by Chris Down
parent ba958bb18b
commit 489fae526d

View File

@ -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,