summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-14 02:34:10 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-16 18:59:07 +0200
commit9156e799a258658cf3f51434708cdb194c13eaa4 (patch)
tree99cfcee2deb8dfd4cadeff17df6113592f5077d7 /src
parent3474ae3c7e1981301d0b35bc89d759ca13f06e8f (diff)
manager: remove unavailable/redundant entries from default controllers list
Diffstat (limited to 'src')
-rw-r--r--src/core/cgroup.c41
-rw-r--r--src/core/cgroup.h1
-rw-r--r--src/core/manager.c5
3 files changed, 43 insertions, 4 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 3334f216a2..b1e22e0ac3 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -30,6 +30,7 @@
#include "cgroup.h"
#include "cgroup-util.h"
#include "log.h"
+#include "strv.h"
int cgroup_bonding_realize(CGroupBonding *b) {
int r;
@@ -305,7 +306,8 @@ int manager_setup_cgroup(Manager *m) {
}
/* 1. Determine hierarchy */
- if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 0, &current)) < 0) {
+ r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 0, &current);
+ if (r < 0) {
log_error("Cannot determine cgroup we are running in: %s", strerror(-r));
goto finish;
}
@@ -352,7 +354,8 @@ int manager_setup_cgroup(Manager *m) {
log_debug("Release agent already installed.");
/* 4. Realize the group */
- if ((r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, 0)) < 0) {
+ r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, 0);
+ if (r < 0) {
log_error("Failed to create root cgroup hierarchy: %s", strerror(-r));
goto finish;
}
@@ -361,7 +364,8 @@ int manager_setup_cgroup(Manager *m) {
if (m->pin_cgroupfs_fd >= 0)
close_nointr_nofail(m->pin_cgroupfs_fd);
- if ((m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK)) < 0) {
+ m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK);
+ if (r < 0) {
log_error("Failed to open pin file: %m");
r = -errno;
goto finish;
@@ -369,6 +373,8 @@ int manager_setup_cgroup(Manager *m) {
log_debug("Created root group.");
+ manager_shorten_default_controllers(m);
+
finish:
free(current);
free(path);
@@ -391,6 +397,35 @@ void manager_shutdown_cgroup(Manager *m, bool delete) {
m->cgroup_hierarchy = NULL;
}
+void manager_shorten_default_controllers(Manager *m) {
+ char **f, **t;
+
+ strv_uniq(m->default_controllers);
+
+ if (!m->default_controllers)
+ return;
+
+ for (f = m->default_controllers, t = m->default_controllers; *f; f++) {
+
+ if (!streq(*f, "systemd") && !streq(*f, "name=systemd")) {
+ char *cc;
+
+ cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(*f));
+ strcpy(stpcpy(cc, "/sys/fs/cgroup/"), *f);
+
+ if (access(cc, F_OK) >= 0) {
+ *(t++) = *f;
+ continue;
+ }
+ }
+
+ log_debug("Controller %s not available or redundant, removing from default controllers list.", *f);
+ free(*f);
+ }
+
+ *t = NULL;
+}
+
int cgroup_bonding_get(Manager *m, const char *cgroup, CGroupBonding **bonding) {
CGroupBonding *b;
char *p;
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index 95f09e0019..dd2e6a4aee 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -85,6 +85,7 @@ pid_t cgroup_bonding_search_main_pid_list(CGroupBonding *b);
int manager_setup_cgroup(Manager *m);
void manager_shutdown_cgroup(Manager *m, bool delete);
+void manager_shorten_default_controllers(Manager *m);
int cgroup_bonding_get(Manager *m, const char *cgroup, CGroupBonding **bonding);
int cgroup_notify_empty(Manager *m, const char *group);
diff --git a/src/core/manager.c b/src/core/manager.c
index c8ac29be5b..44690525ea 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -3165,12 +3165,15 @@ int manager_set_default_controllers(Manager *m, char **controllers) {
assert(m);
- if (!(l = strv_copy(controllers)))
+ l = strv_copy(controllers);
+ if (!l)
return -ENOMEM;
strv_free(m->default_controllers);
m->default_controllers = l;
+ manager_shorten_default_controllers(m);
+
return 0;
}