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 415fc41cea.
This commit is contained in:
Lennart Poettering
2017-02-24 17:52:58 +01:00
parent fc9ae7178e
commit b4cccbc13a
12 changed files with 184 additions and 74 deletions
+10 -4
View File
@@ -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);
+8 -2
View File
@@ -991,7 +991,10 @@ static int mount_legacy_cgns_supported(
return r;
}
if (cg_all_unified())
r = cg_all_unified();
if (r < 0)
return r;
if (r > 0)
goto skip_controllers;
controllers = set_new(&string_hash_ops);
@@ -1094,7 +1097,10 @@ static int mount_legacy_cgns_unsupported(
return r;
}
if (cg_all_unified())
r = cg_all_unified();
if (r < 0)
return r;
if (r > 0)
goto skip_controllers;
controllers = set_new(&string_hash_ops);
+5 -2
View File
@@ -333,7 +333,10 @@ static int detect_unified_cgroup_hierarchy(const char *directory) {
}
/* Otherwise inherit the default from the host system */
if (cg_all_unified()) {
r = cg_all_unified();
if (r < 0)
return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
if (r > 0) {
/* Unified cgroup hierarchy support was added in 230. Unfortunately the detection
* routine only detects 231, so we'll have a false negative here for 230. */
r = systemd_installation_has_version(directory, 230);
@@ -343,7 +346,7 @@ static int detect_unified_cgroup_hierarchy(const char *directory) {
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
else
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
} else if (cg_unified(SYSTEMD_CGROUP_CONTROLLER)) {
} else if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0) {
/* Mixed cgroup hierarchy support was added in 233 */
r = systemd_installation_has_version(directory, 233);
if (r < 0)