X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcgroup.c;h=ca19a4fd4768ef55910e64f5337e0184402d6ab3;hp=392736f987f82d1b23f3ce9705005e3dc618e99e;hb=9534ce54858c67363b841cdbdc315140437bfdb4;hpb=bd40a2d830265cdd36eb19576bdbe8e41dd527ee diff --git a/src/cgroup.c b/src/cgroup.c index 392736f98..ca19a4fd4 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -140,7 +140,7 @@ int cgroup_bonding_install_list(CGroupBonding *first, pid_t pid) { return 0; } -int cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s) { +int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, Set *s) { assert(b); assert(sig >= 0); @@ -148,10 +148,10 @@ int cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s) { if (!b->realized || !b->ours) return 0; - return cg_kill_recursive(b->controller, b->path, sig, true, false, s); + return cg_kill_recursive(b->controller, b->path, sig, sigcont, true, false, s); } -int cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s) { +int cgroup_bonding_kill_list(CGroupBonding *first, int sig, bool sigcont, Set *s) { CGroupBonding *b; Set *allocated_set = NULL; int ret = -EAGAIN, r; @@ -161,7 +161,7 @@ int cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s) { return -ENOMEM; LIST_FOREACH(by_unit, b, first) { - if ((r = cgroup_bonding_kill(b, sig, s)) < 0) { + if ((r = cgroup_bonding_kill(b, sig, sigcont, s)) < 0) { if (r == -EAGAIN || r == -ESRCH) continue; @@ -225,9 +225,17 @@ int manager_setup_cgroup(Manager *m) { assert(m); + /* 0. Be nice to Ingo Molnar #628004 */ + if (path_is_mount_point("/sys/fs/cgroup/systemd") <= 0) { + log_warning("No control group support available, not creating root group."); + return 0; + } + /* 1. Determine hierarchy */ - if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 0, ¤t)) < 0) + if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 0, ¤t)) < 0) { + log_error("Cannot determine cgroup we are running in: %s", strerror(-r)); goto finish; + } if (m->running_as == MANAGER_SYSTEM) strcpy(suffix, "/system"); @@ -246,14 +254,17 @@ int manager_setup_cgroup(Manager *m) { /* We need a new root cgroup */ m->cgroup_hierarchy = NULL; if (asprintf(&m->cgroup_hierarchy, "%s%s", streq(current, "/") ? "" : current, suffix) < 0) { + log_error("Out of memory"); r = -ENOMEM; goto finish; } } /* 2. Show data */ - if ((r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, NULL, &path)) < 0) + if ((r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, NULL, &path)) < 0) { + log_error("Cannot find cgroup mount point: %s", strerror(-r)); goto finish; + } log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path); @@ -276,6 +287,7 @@ int manager_setup_cgroup(Manager *m) { 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) { + log_error("Failed to open pin file: %m"); r = -errno; goto finish; } @@ -403,7 +415,7 @@ char *cgroup_bonding_to_string(CGroupBonding *b) { pid_t cgroup_bonding_search_main_pid(CGroupBonding *b) { FILE *f; - pid_t pid = 0, npid; + pid_t pid = 0, npid, mypid; assert(b); @@ -413,15 +425,22 @@ pid_t cgroup_bonding_search_main_pid(CGroupBonding *b) { if (cg_enumerate_processes(b->controller, b->path, &f) < 0) return 0; + mypid = getpid(); + while (cg_read_pid(f, &npid) > 0) { + pid_t ppid; if (npid == pid) continue; + /* Ignore processes that aren't our kids */ + if (get_parent_of_pid(npid, &ppid) >= 0 && ppid != mypid) + continue; + if (pid != 0) { - /* Dang, there's more than one PID in this - * group, so we don't know what process is the - * main process. */ + /* Dang, there's more than one daemonized PID + in this group, so we don't know what process + is the main process. */ pid = 0; break; }