From 2aeb6b04aa176ef63e3c80e808b0825f52f9d667 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 21 Aug 2017 21:41:13 +0000 Subject: Use waitpid()/EINTR idiom for the specific pid, rather than generic wait(), in case the parent process was started with a dangling child. This style ensures any potential parent:child interlock isn't disrupted due to the "wrong" child being waited on first. Then the other other childs can safely zombie. ok millert jca brynet --- usr.bin/sendbug/sendbug.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'usr.bin/sendbug/sendbug.c') diff --git a/usr.bin/sendbug/sendbug.c b/usr.bin/sendbug/sendbug.c index b06a823855b..cf3385b46ae 100644 --- a/usr.bin/sendbug/sendbug.c +++ b/usr.bin/sendbug/sendbug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sendbug.c,v 1.77 2016/10/18 20:07:35 kettenis Exp $ */ +/* $OpenBSD: sendbug.c,v 1.78 2017/08/21 21:41:13 deraadt Exp $ */ /* * Written by Ray Lai . @@ -277,9 +277,10 @@ editit(const char *pathname) execv(_PATH_BSHELL, argp); _exit(127); } - while (waitpid(pid, &st, 0) == -1) + while (waitpid(pid, &st, 0) == -1) { if (errno != EINTR) goto fail; + } if (!WIFEXITED(st)) errno = EINTR; else @@ -317,12 +318,13 @@ int sendmail(const char *pathname) { int filedes[2]; + pid_t pid; if (pipe(filedes) == -1) { warn("pipe: unsent report in %s", pathname); return (-1); } - switch (fork()) { + switch ((pid = fork())) { case -1: warn("fork error: unsent report in %s", pathname); @@ -349,7 +351,10 @@ sendmail(const char *pathname) return (-1); } close(filedes[1]); - wait(NULL); + while (waitpid(pid, NULL, 0) == -1) { + if (errno != EINTR) + break; + } break; } return (0); -- cgit v1.2.3-59-g8ed1b