From: Todd C. Miller Date: Mon, 9 Aug 2010 10:34:55 +0000 (-0400) Subject: Fix waitpid() loop termination condition. X-Git-Tag: SUDO_1_7_5~194 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39b2ddb43661782b201801486b32edafacc5aef4;p=sudo Fix waitpid() loop termination condition. --HG-- branch : 1.7 --- diff --git a/exec.c b/exec.c index 93316a001..a15403cc2 100644 --- a/exec.c +++ b/exec.c @@ -260,21 +260,22 @@ sudo_execve(path, argv, envp, uid, cstat, dowait, bgmode) #else pid = wait(&status); #endif - if (pid == child) { - if (!log_io) { - if (WIFSTOPPED(status)) { - /* Child may not have privs to suspend us itself. */ - kill(getpid(), WSTOPSIG(status)); - } else { - /* Child has exited, we are done. */ - cstat->type = CMD_WSTATUS; - cstat->val = status; - return 0; - } + } while (pid == -1 && errno == EINTR); + if (pid == child) { + /* If not logging I/O and child has exited we are done. */ + if (!log_io) { + if (WIFSTOPPED(status)) { + /* Child may not have privs to suspend us itself. */ + kill(getpid(), WSTOPSIG(status)); + } else { + /* Child has exited, we are done. */ + cstat->type = CMD_WSTATUS; + cstat->val = status; + return 0; } - /* Else we get ECONNRESET on sv[0] if child dies. */ } - } while (pid != -1 || errno == EINTR); + /* Else we get ECONNRESET on sv[0] if child dies. */ + } } zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));