summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTejun Heo <htejun@fb.com>2016-11-21 14:45:53 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-18 17:51:17 -0500
commitb6629c4b9f82f5801af186e975b0220bf066ddbe (patch)
tree23e89baf9c90615f92c0cc9af28f098b8146f2f7 /src
parent415fc41ceaeada2e32639f24f134b1c248b9e43f (diff)
core: make SYSTEMD_CGROUP_CONTROLLER a special string
SYSTEMD_CGROUP_CONTROLLER is currently defined as "name=systemd" which cgroup utility functions interpret as a named cgroup hierarchy with the specified named. With the planned cgroup hybrid mode changes, SYSTEMD_CGROUP_CONTROLLER would map to different hierarchy names. This patch makes SYSTEMD_CGROUP_CONTROLLER a special string "_systemd" which is substituted to "name=systemd" by the cgroup utility functions. This allows the callers to address the systemd hierarchy without actually specifying the hierarchy name allowing the cgroup utility functions to map it to whatever is appropriate. Note that SYSTEMD_CGROUP_CONTROLLER was already special on full unified cgroup hierarchy even before this patch.
Diffstat (limited to 'src')
-rw-r--r--src/basic/cgroup-util.c20
-rw-r--r--src/basic/def.h3
-rw-r--r--src/core/cgroup.c2
3 files changed, 19 insertions, 6 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 48623fb235..67c2d3a681 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -542,6 +542,9 @@ static const char *controller_to_dirname(const char *controller) {
* just cuts off the name= prefixed used for named
* hierarchies, if it is specified. */
+ if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
+ controller = SYSTEMD_CGROUP_CONTROLLER_LEGACY;
+
e = startswith(controller, "name=");
if (e)
return e;
@@ -912,7 +915,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX];
- const char *fs;
+ const char *fs, *controller_str;
size_t cs = 0;
bool unified;
@@ -926,8 +929,14 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
controller = SYSTEMD_CGROUP_CONTROLLER;
unified = cg_unified(controller);
- if (!unified)
- cs = strlen(controller);
+ if (!unified) {
+ if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
+ controller_str = SYSTEMD_CGROUP_CONTROLLER_LEGACY;
+ else
+ controller_str = controller;
+
+ cs = strlen(controller_str);
+ }
fs = procfs_file_alloca(pid, "cgroup");
f = fopen(fs, "re");
@@ -964,7 +973,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
*e = 0;
FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
- if (k == cs && memcmp(word, controller, cs) == 0) {
+ if (k == cs && memcmp(word, controller_str, cs) == 0) {
found = true;
break;
}
@@ -1810,6 +1819,9 @@ bool cg_controller_is_valid(const char *p) {
if (!p)
return false;
+ if (streq(p, SYSTEMD_CGROUP_CONTROLLER))
+ return true;
+
s = startswith(p, "name=");
if (s)
p = s;
diff --git a/src/basic/def.h b/src/basic/def.h
index 2266eff650..3ba275f64b 100644
--- a/src/basic/def.h
+++ b/src/basic/def.h
@@ -36,7 +36,8 @@
/* The default value for the net.unix.max_dgram_qlen sysctl */
#define DEFAULT_UNIX_MAX_DGRAM_QLEN 512UL
-#define SYSTEMD_CGROUP_CONTROLLER "name=systemd"
+#define SYSTEMD_CGROUP_CONTROLLER_LEGACY "name=systemd"
+#define SYSTEMD_CGROUP_CONTROLLER "_systemd"
#define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
#define SIGNALS_IGNORE SIGPIPE
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 17e0857729..fbb711782e 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -1799,7 +1799,7 @@ int manager_setup_cgroup(Manager *m) {
else if (cg_unified(SYSTEMD_CGROUP_CONTROLLER))
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);
+ log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER_LEGACY ". File system hierarchy is at %s.", path);
if (!m->test_run) {
const char *scope_path;