summaryrefslogtreecommitdiffstats
path: root/usr.bin/sendbug/sendbug.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2017-08-21 21:41:13 +0000
committerderaadt <deraadt@openbsd.org>2017-08-21 21:41:13 +0000
commit2aeb6b04aa176ef63e3c80e808b0825f52f9d667 (patch)
treef878ca55fb6ebedeea2cc01fc560d344bd407c0c /usr.bin/sendbug/sendbug.c
parentMove the kernel relinking code from /etc/rc into a seperate script (diff)
downloadwireguard-openbsd-2aeb6b04aa176ef63e3c80e808b0825f52f9d667.tar.xz
wireguard-openbsd-2aeb6b04aa176ef63e3c80e808b0825f52f9d667.zip
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
Diffstat (limited to 'usr.bin/sendbug/sendbug.c')
-rw-r--r--usr.bin/sendbug/sendbug.c13
1 files changed, 9 insertions, 4 deletions
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 <ray@cyth.net>.
@@ -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);