pid_t ppid;
int r;
+ if (pid < 0)
+ return -ESRCH;
+
if (pid <= 1)
return false;
return ppid == getpid_cached();
}
+int pidref_is_my_child(const PidRef *pid) {
+ int r, result;
+
+ if (!pidref_is_set(pid))
+ return -ESRCH;
+
+ result = pid_is_my_child(pid->pid);
+ if (result < 0)
+ return result;
+
+ r = pidref_verify(pid);
+ if (r < 0)
+ return r;
+
+ return result;
+}
+
bool pid_is_unwaited(pid_t pid) {
/* Checks whether a PID is still valid at all, including a zombie */
int pidref_is_alive(const PidRef *pidref);
bool pid_is_unwaited(pid_t pid);
int pid_is_my_child(pid_t pid);
+int pidref_is_my_child(const PidRef *pidref);
int pid_from_same_root_fs(pid_t pid);
bool is_main_thread(void);
if (pidref_equal(&pidref, &npidref)) /* seen already, cgroupfs reports duplicates! */
continue;
- if (pid_is_my_child(npidref.pid) == 0) /* ignore processes further down the tree */
+ if (pidref_is_my_child(&npidref) <= 0) /* ignore processes further down the tree */
continue;
if (pidref_is_set(&pidref) != 0)
}
static int service_set_main_pidref(Service *s, PidRef *pidref) {
+ int r;
+
assert(s);
/* Takes ownership of the specified pidref on success, but not on failure. */
s->main_pid = TAKE_PIDREF(*pidref);
s->main_pid_known = true;
- s->main_pid_alien = pid_is_my_child(s->main_pid.pid) == 0;
- if (s->main_pid_alien)
+ r = pidref_is_my_child(&s->main_pid);
+ if (r < 0)
+ log_unit_warning_errno(UNIT(s), r, "Can't determine if process "PID_FMT" is our child, assuming it is not: %m", s->main_pid.pid);
+ else if (r == 0)
log_unit_warning(UNIT(s), "Supervising process "PID_FMT" which is not our child. We'll most likely not notice when it exits.", s->main_pid.pid);
+ s->main_pid_alien = r <= 0;
return 0;
}