chiark / gitweb /
cgroup: don't recheck all the time whether the systemd hierarchy is mounted, to make...
[elogind.git] / src / cgroup.c
index 64082d0dc6b64140636d1f10ee209e4fa9deecf3..b75fe0bee0c9116f9736b8153db15de1fd1fef67 100644 (file)
@@ -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;
 
@@ -403,26 +403,32 @@ char *cgroup_bonding_to_string(CGroupBonding *b) {
 
 pid_t cgroup_bonding_search_main_pid(CGroupBonding *b) {
         FILE *f;
-        pid_t pid = 0, npid;
-        int r;
+        pid_t pid = 0, npid, mypid;
 
         assert(b);
 
         if (!b->ours)
                 return 0;
 
-        if ((r = cg_enumerate_processes(b->controller, b->path, &f)) < 0)
+        if (cg_enumerate_processes(b->controller, b->path, &f) < 0)
                 return 0;
 
-        while ((r = cg_read_pid(f, &npid)) > 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;
                 }