aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-07-14 02:25:29 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-07-14 02:25:29 +0000
commit92fa728bb15dc7b2a254805993b8b4ece3c6d346 (patch)
tree32fc607f77db598c971be1cd9baa325a807c564d /usr.bin
parent8cabd541f7df54f317de6971991bdb97fd6363fd (diff)
downloadsrc-92fa728bb15dc7b2a254805993b8b4ece3c6d346.tar.gz
src-92fa728bb15dc7b2a254805993b8b4ece3c6d346.zip
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mail/popen.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c
index aef2dff2ac05..9cd4378245d4 100644
--- a/usr.bin/mail/popen.c
+++ b/usr.bin/mail/popen.c
@@ -362,21 +362,30 @@ int wait_status;
int
wait_child(pid_t pid)
{
- sigset_t nset, oset;
struct child *cp;
+ sigset_t nset, oset;
+ pid_t rv = 0;
(void)sigemptyset(&nset);
(void)sigaddset(&nset, SIGCHLD);
- (void)sigprocmask(SIG_BLOCK, &nset, &oset);
-
+ (void)sigprocmask(SIG_BLOCK, &nset, &oset);
+ /*
+ * If we have not already waited on the pid (via sigchild)
+ * wait on it now. Otherwise, use the wait status stashed
+ * by sigchild.
+ */
cp = findchild(pid, 1);
-
- while (!cp->done)
- (void)sigsuspend(&oset);
- wait_status = cp->status;
- delchild(cp);
+ if (cp == NULL || !cp->done)
+ rv = waitpid(pid, &wait_status, 0);
+ else
+ wait_status = cp->status;
+ if (cp != NULL)
+ delchild(cp);
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
- return ((WIFEXITED(wait_status) && WEXITSTATUS(wait_status)) ? -1 : 0);
+ if (rv == -1 || (WIFEXITED(wait_status) && WEXITSTATUS(wait_status)))
+ return -1;
+ else
+ return 0;
}
/*