From 772d6c139c3b87609d4d7b0acd2d0540a438310a Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 15 Jun 2017 19:37:04 +0100 Subject: [PATCH] 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). --- src/service.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.25.1