summaryrefslogtreecommitdiff
path: root/src/shared/cgroup-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-16 19:14:11 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-16 19:15:00 +0200
commitb59e246565337d6c6967059dd15a52a15277433e (patch)
tree3ea65b16f40db14e76ee5437a76c9d2173ea8728 /src/shared/cgroup-util.c
parentb69d29ce049f12d463a589e18561dd10ee8c09f1 (diff)
logind: remove redundant entries from logind's default controller lists too
Diffstat (limited to 'src/shared/cgroup-util.c')
-rw-r--r--src/shared/cgroup-util.c33
1 files changed, 33 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;
+}