summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2019-03-18 11:48:34 +0100
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>2019-10-21 16:37:15 +0200
commitf057aa6bb604845fa10ad569bca306e5e1e8fe0d (patch)
treeb06a12678826cac5cbdffdee761f76b6268d13f1 /src/core
parent1bf923686a6842f222b1ef5f5174511340c75685 (diff)
downloadsystemd-f057aa6bb604845fa10ad569bca306e5e1e8fe0d.tar.gz
process-util: introduce pid_is_my_child() helper
No functional changes. Thanks Renaud Métrich for backporting this to RHEL. Resolves: #1744972
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c7
-rw-r--r--src/core/service.c8
2 files changed, 4 insertions, 11 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 62ab41a288..b7ed07e65b 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -1876,7 +1876,7 @@ void unit_prune_cgroup(Unit *u) {
int unit_search_main_pid(Unit *u, pid_t *ret) {
_cleanup_fclose_ FILE *f = NULL;
- pid_t pid = 0, npid, mypid;
+ pid_t pid = 0, npid;
int r;
assert(u);
@@ -1889,15 +1889,12 @@ int unit_search_main_pid(Unit *u, pid_t *ret) {
if (r < 0)
return r;
- mypid = getpid_cached();
while (cg_read_pid(f, &npid) > 0) {
- pid_t ppid;
if (npid == pid)
continue;
- /* Ignore processes that aren't our kids */
- if (get_process_ppid(npid, &ppid) >= 0 && ppid != mypid)
+ if (pid_is_my_child(npid) == 0)
continue;
if (pid != 0)
diff --git a/src/core/service.c b/src/core/service.c
index 24f167572a..614ba05d89 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -139,8 +139,6 @@ static void service_unwatch_pid_file(Service *s) {
}
static int service_set_main_pid(Service *s, pid_t pid) {
- pid_t ppid;
-
assert(s);
if (pid <= 1)
@@ -159,12 +157,10 @@ static int service_set_main_pid(Service *s, pid_t pid) {
s->main_pid = pid;
s->main_pid_known = true;
+ s->main_pid_alien = pid_is_my_child(pid) == 0;
- if (get_process_ppid(pid, &ppid) >= 0 && ppid != getpid_cached()) {
+ if (s->main_pid_alien)
log_unit_warning(UNIT(s), "Supervising process "PID_FMT" which is not our child. We'll most likely not notice when it exits.", pid);
- s->main_pid_alien = true;
- } else
- s->main_pid_alien = false;
return 0;
}