X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fcgroup-util.c;h=d34c142729da00f229d4e9dc103fd4ba2c5711d1;hp=8ceb382820d8e9adea51df7199b79567442b43c4;hb=018ef268b1667ba0dbfc15804ab33deed6092147;hpb=b69d29ce049f12d463a589e18561dd10ee8c09f1 diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 8ceb38282..d34c14272 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; @@ -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) { - char *t; + char *t = NULL; if (!(controller || path)) return -EINVAL; @@ -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; +}