X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcgroup.c;h=729cc75e6704cf39e35f98a68eed1ad0f6eb18d4;hp=64082d0dc6b64140636d1f10ee209e4fa9deecf3;hb=e67c3609b18ab09499b361e18addfcfdec853fdd;hpb=d686d8a97bd7945af0a61504392d01a3167b576f diff --git a/src/cgroup.c b/src/cgroup.c index 64082d0dc..729cc75e6 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -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; }