diff options
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r-- | src/core/cgroup.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index c5ca9947e..85575a589 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -37,19 +37,34 @@ #include "stdio-util.h" #include "string-table.h" #include "string-util.h" +//#include "virt.h" #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC) +bool manager_owns_root_cgroup(Manager *m) { + assert(m); + + /* Returns true if we are managing the root cgroup. Note that it isn't sufficient to just check whether the + * group root path equals "/" since that will also be the case if CLONE_NEWCGROUP is in the mix. Since there's + * appears to be no nice way to detect whether we are in a CLONE_NEWCGROUP namespace we instead just check if + * we run in any kind of container virtualization. */ + + if (detect_container() > 0) + return false; + + return isempty(m->cgroup_root) || path_equal(m->cgroup_root, "/"); +} + bool unit_has_root_cgroup(Unit *u) { assert(u); - /* Returns whether this unit manages the root cgroup. Note that this is different from being named "-.slice", - * as inside of containers the root slice won't be identical to the root cgroup. */ + /* Returns whether this unit manages the root cgroup. This will return true if this unit is the root slice and + * the manager manages the root cgroup. */ - if (!u->cgroup_path) + if (!manager_owns_root_cgroup(u->manager)) return false; - return isempty(u->cgroup_path) || path_equal(u->cgroup_path, "/"); + return unit_has_name(u, SPECIAL_ROOT_SLICE); } #if 0 /// UNNEEDED by elogind @@ -59,7 +74,9 @@ static void cgroup_compat_warn(void) { if (cgroup_compat_warned) return; - log_warning("cgroup compatibility translation between legacy and unified hierarchy settings activated. See cgroup-compat debug messages for details."); + log_warning("cgroup compatibility translation between legacy and unified hierarchy settings activated. " + "See cgroup-compat debug messages for details."); + cgroup_compat_warned = true; } |