From: Lennart Poettering Date: Fri, 17 Nov 2017 12:05:30 +0000 (+0100) Subject: nspawn: rework mount_systemd_cgroup_writable() a bit X-Git-Tag: v236~152^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea9053c5f8eaae748683848ed807e7dbf30d85a7;p=thirdparty%2Fsystemd.git nspawn: rework mount_systemd_cgroup_writable() a bit We shouldn't call alloca() as part of function calls, that's not really defined in C. Hence, let's first do our stack allocations, and then invoke functions. Also, some coding style fixes, and minor shuffling around. No functional changes. --- diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index c8c941cdfdb..69707cb7f98 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -1213,23 +1213,25 @@ int mount_cgroups( if (unified_requested >= CGROUP_UNIFIED_ALL) return mount_unified_cgroups(dest); - else if (use_cgns) + if (use_cgns) return mount_legacy_cgns_supported(dest, unified_requested, userns, uid_shift, uid_range, selinux_apifs_context); return mount_legacy_cgns_unsupported(dest, unified_requested, userns, uid_shift, uid_range, selinux_apifs_context); } -static int mount_systemd_cgroup_writable_one(const char *systemd_own, const char *systemd_root) -{ +static int mount_systemd_cgroup_writable_one(const char *root, const char *own) { int r; + assert(root); + assert(own); + /* Make our own cgroup a (writable) bind mount */ - r = mount_verbose(LOG_ERR, systemd_own, systemd_own, NULL, MS_BIND, NULL); + r = mount_verbose(LOG_ERR, own, own, NULL, MS_BIND, NULL); if (r < 0) return r; /* And then remount the systemd cgroup root read-only */ - return mount_verbose(LOG_ERR, NULL, systemd_root, NULL, + return mount_verbose(LOG_ERR, NULL, root, NULL, MS_BIND|MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY, NULL); } @@ -1238,6 +1240,7 @@ int mount_systemd_cgroup_writable( CGroupUnified unified_requested) { _cleanup_free_ char *own_cgroup_path = NULL; + const char *root, *own; int r; assert(dest); @@ -1250,19 +1253,27 @@ int mount_systemd_cgroup_writable( if (path_equal(own_cgroup_path, "/")) return 0; - if (unified_requested >= CGROUP_UNIFIED_ALL) - return mount_systemd_cgroup_writable_one(strjoina(dest, "/sys/fs/cgroup", own_cgroup_path), - prefix_roota(dest, "/sys/fs/cgroup")); + if (unified_requested >= CGROUP_UNIFIED_ALL) { - if (unified_requested >= CGROUP_UNIFIED_SYSTEMD) { - r = mount_systemd_cgroup_writable_one(strjoina(dest, "/sys/fs/cgroup/unified", own_cgroup_path), - prefix_roota(dest, "/sys/fs/cgroup/unified")); - if (r < 0) - return r; + root = prefix_roota(dest, "/sys/fs/cgroup"); + own = strjoina(root, own_cgroup_path); + + } else { + + if (unified_requested >= CGROUP_UNIFIED_SYSTEMD) { + root = prefix_roota(dest, "/sys/fs/cgroup/unified"); + own = strjoina(root, own_cgroup_path); + + r = mount_systemd_cgroup_writable_one(root, own); + if (r < 0) + return r; + } + + root = prefix_roota(dest, "/sys/fs/cgroup/systemd"); + own = strjoina(root, own_cgroup_path); } - return mount_systemd_cgroup_writable_one(strjoina(dest, "/sys/fs/cgroup/systemd", own_cgroup_path), - prefix_roota(dest, "/sys/fs/cgroup/systemd")); + return mount_systemd_cgroup_writable_one(root, own); } int setup_volatile_state(