diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-04-16 19:14:11 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-04-16 19:15:00 +0200 |
commit | b59e246565337d6c6967059dd15a52a15277433e (patch) | |
tree | 3ea65b16f40db14e76ee5437a76c9d2173ea8728 /src/shared | |
parent | b69d29ce049f12d463a589e18561dd10ee8c09f1 (diff) |
logind: remove redundant entries from logind's default controller lists too
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cgroup-util.c | 33 | ||||
-rw-r--r-- | src/shared/cgroup-util.h | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 8ceb382820..3cb41c7c5f 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -34,6 +34,7 @@ #include "set.h" #include "macro.h" #include "util.h" +#include "strv.h" int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) { char *fs; @@ -1100,3 +1101,35 @@ int cg_get_user_path(char **path) { *path = p; return 0; } + +char **cg_shorten_controllers(char **controllers) { + char **f, **t; + + controllers = strv_uniq(controllers); + + if (!controllers) + return controllers; + + for (f = controllers, t = controllers; *f; f++) { + char *cc; + + if (streq(*f, "systemd") || streq(*f, SYSTEMD_CGROUP_CONTROLLER)) { + free(*f); + continue; + } + + cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(*f)); + strcpy(stpcpy(cc, "/sys/fs/cgroup/"), *f); + + if (access(cc, F_OK) < 0) { + log_debug("Controller %s is not available, removing from controllers list.", *f); + free(*f); + continue; + } + + *(t++) = *f; + } + + *t = NULL; + return controllers; +} diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h index cc0ce54521..bb156fc259 100644 --- a/src/shared/cgroup-util.h +++ b/src/shared/cgroup-util.h @@ -70,4 +70,6 @@ int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_ int cg_get_user_path(char **path); +char **cg_shorten_controllers(char **controllers); + #endif |