From: Davin McCall Date: Thu, 15 Jun 2017 18:37:04 +0000 (+0100) Subject: Increase priority of service child status watchers. X-Git-Tag: v0.06~66 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=772d6c139c3b87609d4d7b0acd2d0540a438310a;p=oweals%2Fdinit.git Increase priority of service child status watchers. We want to make sure that if we send a signal to a service process, we haven't already reaped that process (since in that case, in theory, the process ID may have been re-used and we will end up signalling the wrong process). --- diff --git a/src/service.cc b/src/service.cc index 764a451..3c802e8 100644 --- a/src/service.cc +++ b/src/service.cc @@ -847,7 +847,11 @@ bool base_process_service::start_ps_process(const std::vector &cmd pid_t forkpid; try { - child_status_listener.add_watch(eventLoop, pipefd[0], IN_EVENTS); + // We add the status listener with a high priority (i.e. low priority value) so that process + // termination is handled early. This means we have always recorded that the process is + // terminated by the time that we handle events that might otherwise cause us to signal the + // process, so we avoid sending a signal to an invalid (and possibly recycled) process ID. + child_status_listener.add_watch(eventLoop, pipefd[0], IN_EVENTS, true, DEFAULT_PRIORITY - 10); child_status_registered = true; forkpid = child_listener.fork(eventLoop);