if (r < 0)
return r;
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified)
assert(path);
assert(pid >= 0);
- if (controller) {
- if (!cg_controller_is_valid(controller))
- return -EINVAL;
- } else
- controller = SYSTEMD_CGROUP_CONTROLLER;
-
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
- if (unified == 0)
+ if (unified == 0) {
+ if (controller) {
+ if (!cg_controller_is_valid(controller))
+ return -EINVAL;
+ } else
+ controller = SYSTEMD_CGROUP_CONTROLLER;
+
cs = strlen(controller);
+ }
fs = procfs_file_alloca(pid, "cgroup");
log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
assert(agent);
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified) /* doesn't apply to unified hierarchy */
_cleanup_free_ char *fs = NULL;
int r, unified;
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified) /* Doesn't apply to unified hierarchy */
if (controller && (isempty(path) || path_equal(path, "/")))
return false;
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
}
#endif // 0
-static thread_local CGroupUnified unified_cache = CGROUP_UNIFIED_UNKNOWN;
-
-static int cg_update_unified(void) {
+static thread_local int unified_cache = -1;
+int cg_all_unified(void) {
struct statfs fs;
/* Checks if we support the unified hierarchy. Returns an
* have any other trouble determining if the unified hierarchy
* is supported. */
- if (unified_cache >= CGROUP_UNIFIED_NONE)
- return 0;
+ if (unified_cache >= 0)
+ return unified_cache;
if (statfs("/sys/fs/cgroup/", &fs) < 0)
return -errno;
#if 0 /// UNNEEDED by elogind
if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
- unified_cache = CGROUP_UNIFIED_ALL;
- else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
#else
/* elogind can not support the unified hierarchy as a controller,
* so always assume a classical hierarchy.
* add such a support. */
if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
#endif // 0
- if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0)
- return -errno;
-
- unified_cache = F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC) ?
- CGROUP_UNIFIED_SYSTEMD : CGROUP_UNIFIED_NONE;
- } else
- return -ENOMEDIUM;
-
- return 0;
-}
-
-int cg_unified(const char *controller) {
-
- int r;
-
- r = cg_update_unified();
- if (r < 0)
- return r;
-
- if (streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER))
- return unified_cache >= CGROUP_UNIFIED_SYSTEMD;
+ unified_cache = true;
+ else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC))
+ unified_cache = false;
else
- return unified_cache >= CGROUP_UNIFIED_ALL;
-}
-
-int cg_all_unified(void) {
+ return -ENOMEDIUM;
- return cg_unified(NULL);
+ return unified_cache;
}
#if 0 /// UNNEEDED by elogind
void cg_unified_flush(void) {
- unified_cache = CGROUP_UNIFIED_UNKNOWN;
+ unified_cache = -1;
}
int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
}
#endif // 0
-typedef enum CGroupUnified {
- CGROUP_UNIFIED_UNKNOWN = -1,
- CGROUP_UNIFIED_NONE = 0, /* Both systemd and controllers on legacy */
- CGROUP_UNIFIED_SYSTEMD = 1, /* Only systemd on unified */
- CGROUP_UNIFIED_ALL = 2, /* Both systemd and controllers on unified */
-} CGroupUnified;
-
/*
* General rules:
*
#if 0 /// UNNEEDED by elogind
int cg_all_unified(void);
-int cg_unified(const char *controller);
void cg_unified_flush(void);
bool cg_is_unified_wanted(void);
#endif // 0
bool cg_is_legacy_wanted(void);
-bool cg_is_unified_systemd_controller_wanted(void);
const char* cgroup_controller_to_string(CGroupController c) _const_;
CGroupController cgroup_controller_from_string(const char *s) _pure_;
return 0;
/* Only applies to the unified hierarchy */
- r = cg_unified(SYSTEMD_CGROUP_CONTROLLER);
+ r = cg_all_unified();
if (r < 0)
return log_unit_error_errno(u, r, "Failed detect whether the unified hierarchy is used: %m");
if (r == 0)
if (!u->cgroup_path)
return -ENOENT;
- if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0) /* On unified we can use proper notifications */
+ if (cg_all_unified() > 0) /* On unified we can use proper notifications */
return 0;
return unit_watch_pids_in_path(u, u->cgroup_path);
int manager_setup_cgroup(Manager *m) {
_cleanup_free_ char *path = NULL;
CGroupController c;
- int r, all_unified, systemd_unified;
+ int r, unified;
char *e;
assert(m);
if (r < 0)
return log_error_errno(r, "Cannot find cgroup mount point: %m");
- all_unified = cg_all_unified();
- systemd_unified = cg_unified(SYSTEMD_CGROUP_CONTROLLER);
-
- if (all_unified < 0 || systemd_unified < 0)
- return log_error_errno(all_unified < 0 ? all_unified : systemd_unified,
- "Couldn't determine if we are running in the unified hierarchy: %m");
-
- if (all_unified > 0)
+ unified = cg_all_unified();
+ if (unified < 0)
+ return log_error_errno(r, "Couldn't determine if we are running in the unified hierarchy: %m");
+ if (unified > 0)
log_debug("Unified cgroup hierarchy is located at %s.", path);
- else if (systemd_unified > 0)
- log_debug("Unified cgroup hierarchy is located at %s. Controllers are on legacy hierarchies.", path);
else
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path);
const char *scope_path;
/* 3. Install agent */
- if (systemd_unified) {
+ if (unified) {
/* In the unified hierarchy we can get
* cgroup empty notifications via inotify. */
return log_error_errno(errno, "Failed to open pin file: %m");
/* 6. Always enable hierarchical support if it exists... */
- if (!all_unified)
+ if (!unified)
(void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
}