diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-02-24 17:52:58 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-02-24 17:52:58 +0100 |
commit | b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c (patch) | |
tree | 14313f0bd5cd2dad79fda852663d9038f81a35ad /src/nspawn/nspawn-cgroup.c | |
parent | cgroup-util: check unified_cache before invoking streq() (diff) | |
download | systemd-b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c.tar.xz systemd-b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c.zip |
cgroup: change cg_unified() to possibly return errors again
We use our cgroup APIs in various contexts, including from our libraries
sd-login, sd-bus. As we don#t control those environments we can't rely
that the unified cgroup setup logic succeeds, and hence really shouldn't
assert on it.
This more or less reverts 415fc41ceaeada2e32639f24f134b1c248b9e43f.
Diffstat (limited to 'src/nspawn/nspawn-cgroup.c')
-rw-r--r-- | src/nspawn/nspawn-cgroup.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index 4678a7e349..3ca067e5bc 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -78,9 +78,12 @@ int sync_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t arg_uid_shift) char tree[] = "/tmp/unifiedXXXXXX", pid_string[DECIMAL_STR_MAX(pid) + 1]; bool undo_mount = false; const char *fn; - int r; + int r, unified_controller; - if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) == (unified_requested >= CGROUP_UNIFIED_SYSTEMD)) + unified_controller = cg_unified(SYSTEMD_CGROUP_CONTROLLER); + if (unified_controller < 0) + return log_error_errno(unified_controller, "Failed to determine whether the systemd hierarchy is unified: %m"); + if ((unified_controller > 0) == (unified_requested >= CGROUP_UNIFIED_SYSTEMD)) return 0; /* When the host uses the legacy cgroup setup, but the @@ -96,7 +99,7 @@ int sync_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t arg_uid_shift) if (!mkdtemp(tree)) return log_error_errno(errno, "Failed to generate temporary mount point for unified hierarchy: %m"); - if (cg_unified(SYSTEMD_CGROUP_CONTROLLER)) + if (unified_controller > 0) r = mount_verbose(LOG_ERR, "cgroup", tree, "cgroup", MS_NOSUID|MS_NOEXEC|MS_NODEV, "none,name=systemd,xattr"); else @@ -150,7 +153,10 @@ int create_subcgroup(pid_t pid, CGroupUnified unified_requested) { if (unified_requested == CGROUP_UNIFIED_NONE) return 0; - if (!cg_unified(SYSTEMD_CGROUP_CONTROLLER)) + r = cg_unified(SYSTEMD_CGROUP_CONTROLLER); + if (r < 0) + return log_error_errno(r, "Failed to determine whether the systemd controller is unified: %m"); + if (r == 0) return 0; r = cg_mask_supported(&supported); |