chiark / gitweb /
silence a bunch of gcc warnings
[elogind.git] / src / shared / cgroup-util.c
index 8ceb382820d8e9adea51df7199b79567442b43c4..d34c142729da00f229d4e9dc103fd4ba2c5711d1 100644 (file)
@@ -34,6 +34,7 @@
 #include "set.h"
 #include "macro.h"
 #include "util.h"
 #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;
 
 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
         char *fs;
@@ -513,7 +514,7 @@ static const char *normalize_controller(const char *controller) {
 }
 
 static int join_path(const char *controller, const char *path, const char *suffix, char **fs) {
 }
 
 static int join_path(const char *controller, const char *path, const char *suffix, char **fs) {
-        char *t;
+        char *t = NULL;
 
         if (!(controller || path))
                 return -EINVAL;
 
         if (!(controller || path))
                 return -EINVAL;
@@ -1100,3 +1101,35 @@ int cg_get_user_path(char **path) {
         *path = p;
         return 0;
 }
         *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;
+}