From 040d921fa16b0c7daafd47292b9fb81db9bbdbb8 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 30 Dec 2018 10:11:20 -0600 Subject: [PATCH] Fix check for valid disowned pgids The function `add_disowned_pgid` adds process *group* ids and not process ids. It multiplies the value by negative 1 to indicate a wait on a process group, so the original value must be positive. --- src/proc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index a6da0c122..f31b720c4 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -354,10 +354,11 @@ typedef unsigned int process_generation_count_t; static std::vector s_disowned_pids; void add_disowned_pgid(pid_t pgid) { - // NEVER add our own pgid, or one of the special values, - // or waiting for it will - // snag other processes away. - if (pgid != getpgrp() && (pgid > 0 || pgid < -1)) { + // NEVER add our own (or an invalid) pgid as they are not unique to only + // one job, and may result in a deadlock if we attempt the wait. + if (pgid != getpgrp() && pgid > 0) { + // waitpid(2) is signalled to wait on a process group rather than a + // process id by using the negative of its value. s_disowned_pids.push_back(pgid * -1); } }