summaryrefslogtreecommitdiff
path: root/src/cgroup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-02-13 18:52:02 +0100
committerLennart Poettering <lennart@poettering.net>2011-02-13 18:52:02 +0100
commit2633eb8317623138f585957fcf8337a99fb1528f (patch)
tree378fcdc3ebd45f0a10cd910637a639573872f142 /src/cgroup.c
parent3185a36b05d53757a412f847d8c510978b9b00f0 (diff)
service: when guessing the main PID don't consider processes that aren't our children
Diffstat (limited to 'src/cgroup.c')
-rw-r--r--src/cgroup.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cgroup.c b/src/cgroup.c
index 392736f987..729cc75e67 100644
--- a/src/cgroup.c
+++ b/src/cgroup.c
@@ -403,7 +403,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 +413,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;
}