We check whether the process exists using kill. We were treating any
error return as meaning the process ID was invalid, but in fact we may
simply not have permission to signal the process (if we are not being
run as root and the service process is suid).
pid_t wait_r = waitpid(pid, exit_status, WNOHANG);
if (wait_r == -1 && errno == ECHILD) {
// We can't track this child - check process exists:
- if (kill(pid, 0) == 0) {
+ if (kill(pid, 0) == 0 || errno != ESRCH) {
tracking_child = false;
return pid_result_t::OK;
}