diff options
author | Sven Eden <yamakuzure@gmx.net> | 2017-02-16 06:16:10 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 10:23:13 +0100 |
commit | c190efa0e56ab46fd484e489f31a7622bf041de6 (patch) | |
tree | 197a7c434e620d519439b0345bc9ce526985c729 /src | |
parent | 99015227d48e9e04fe72ecf1f0a09a7c79ac575e (diff) |
Detect running cgroup controller.
elogind has to run on any system, no matter which init system is in
control of the cgroups. So instead of hardcoding "name=foo",
configure now greps 1: in /proc/self/cgroup - which is hopefully
the right choice. (Well, to be honest, if it isn't, something is
really wrong with the running system...)
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/cgroup-util.c | 52 | ||||
-rw-r--r-- | src/basic/def.h | 4 |
2 files changed, 29 insertions, 27 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index cd5db6f69..92d09f0b5 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -570,7 +570,7 @@ static int controller_is_accessible(const char *controller) { * the unified hierarchy. */ if (streq(controller, ELOGIND_CGROUP_CONTROLLER)) - return 0; + return 0; if (startswith(controller, "name=")) return -EOPNOTSUPP; @@ -581,8 +581,8 @@ static int controller_is_accessible(const char *controller) { dn = controller_to_dirname(controller); cc = strjoina("/sys/fs/cgroup/", dn); - if (laccess(cc, F_OK) < 0) - return -errno; + if (laccess(cc, F_OK) < 0) + return -errno; } return 0; @@ -811,11 +811,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) { if (unified < 0) return unified; if (unified == 0) { - if (controller) { - if (!cg_controller_is_valid(controller)) - return -EINVAL; - } else - controller = ELOGIND_CGROUP_CONTROLLER; + if (controller) { + if (!cg_controller_is_valid(controller)) + return -EINVAL; + } else + controller = ELOGIND_CGROUP_CONTROLLER; cs = strlen(controller); } @@ -840,29 +840,29 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) { continue; } else { char *l; - size_t k; - const char *word, *state; - bool found = false; + size_t k; + const char *word, *state; + bool found = false; - l = strchr(line, ':'); - if (!l) - continue; + l = strchr(line, ':'); + if (!l) + continue; - l++; - e = strchr(l, ':'); - if (!e) - continue; + l++; + e = strchr(l, ':'); + if (!e) + continue; - *e = 0; - FOREACH_WORD_SEPARATOR(word, k, l, ",", state) { - if (k == cs && memcmp(word, controller, cs) == 0) { - found = true; - break; + *e = 0; + FOREACH_WORD_SEPARATOR(word, k, l, ",", state) { + if (k == cs && memcmp(word, controller, cs) == 0) { + found = true; + break; + } } - } - if (!found) - continue; + if (!found) + continue; } p = strdup(e + 1); diff --git a/src/basic/def.h b/src/basic/def.h index 00f9f2f94..f4ca626d2 100644 --- a/src/basic/def.h +++ b/src/basic/def.h @@ -35,7 +35,9 @@ * the watchdog pings will keep the loop busy. */ #define DEFAULT_EXIT_USEC (30*USEC_PER_SEC) -#define ELOGIND_CGROUP_CONTROLLER "name=elogind" +#ifndef ELOGIND_CGROUP_CONTROLLER +# define ELOGIND_CGROUP_CONTROLLER "name=elogind" +#endif #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT #define SIGNALS_IGNORE SIGPIPE |