logind: remove redundant entries from logind's default controller lists too

This commit is contained in:
Lennart Poettering 2012-04-16 19:14:11 +02:00
parent b69d29ce04
commit b59e246565
7 changed files with 41 additions and 36 deletions

4
TODO
View File

@ -17,8 +17,6 @@ Features:
* suspend/hibernate/hybrid support, auto-suspend logic with idle hint
* filter default cgroups in logind too
* udev: remove /sys and /dev configurability
* udev: find a way to tell udev to not cancel firmware requests when running in initramfs
@ -286,8 +284,6 @@ Features:
* add systemctl switch to dump transaction without executing it
* suspend, resume support?
* drop cap bounding set in readahead and other services
External:

View File

@ -373,7 +373,7 @@ int manager_setup_cgroup(Manager *m) {
log_debug("Created root group.");
manager_shorten_default_controllers(m);
cg_shorten_controllers(m->default_controllers);
finish:
free(current);
@ -397,35 +397,6 @@ 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;

View File

@ -85,7 +85,6 @@ 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);

View File

@ -63,6 +63,7 @@
#include "exit-status.h"
#include "virt.h"
#include "watchdog.h"
#include "cgroup-util.h"
/* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
#define GC_QUEUE_ENTRIES_MAX 16
@ -3172,7 +3173,7 @@ int manager_set_default_controllers(Manager *m, char **controllers) {
strv_free(m->default_controllers);
m->default_controllers = l;
manager_shorten_default_controllers(m);
cg_shorten_controllers(m->default_controllers);
return 0;
}

View File

@ -1205,6 +1205,9 @@ int manager_startup(Manager *m) {
assert(m);
assert(m->epoll_fd <= 0);
cg_shorten_controllers(m->reset_controllers);
cg_shorten_controllers(m->controllers);
m->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (m->epoll_fd < 0)
return -errno;

View File

@ -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;
}

View File

@ -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