From 9edf1c8ee349c85b1f95a9c3d4369ffda1410259 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Jun 2017 22:27:40 -0400 Subject: nspawn: Parse UNIFIED_CGROUP_HIERARCHY similarly to any other arg --- src/nspawn/nspawn.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 570b170b16..c0b4c3142d 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -320,25 +320,10 @@ static int custom_mounts_prepare(void) { return 0; } -static int detect_unified_cgroup_hierarchy(const char *directory) { - const char *e; +static int pick_cgroup_version(const char *directory) { int r; CGroupUnified outer; - /* Allow the user to control whether the unified hierarchy is used */ - e = getenv("UNIFIED_CGROUP_HIERARCHY"); - if (e) { - r = parse_boolean(e); - if (r < 0) - return log_error_errno(r, "Failed to parse $UNIFIED_CGROUP_HIERARCHY."); - if (r > 0) - arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL; - else - arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE; - - return 0; - } - r = cg_version(&outer); if (r < 0) return log_error_errno(r, "Failed to determine whether the unified cgroups hierarchy is used: %m"); @@ -1172,6 +1157,17 @@ static int parse_argv(int argc, char *argv[]) { else arg_use_cgns = r && cg_ns_supported(); + e = getenv("UNIFIED_CGROUP_HIERARCHY"); + if (e) { + r = parse_boolean(e); + if (r < 0) + return log_error_errno(r, "Failed to parse $UNIFIED_CGROUP_HIERARCHY."); + if (r > 0) + arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL; + else + arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE; + } + return 1; } @@ -4209,9 +4205,11 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; - r = detect_unified_cgroup_hierarchy(arg_directory); - if (r < 0) - goto finish; + if (arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_UNKNOWN) { + r = pick_cgroup_version(arg_directory); + if (r < 0) + goto finish; + } interactive = isatty(STDIN_FILENO) > 0 && -- cgit v1.2.3-54-g00ecf