summaryrefslogtreecommitdiff
path: root/usr.bin/tput
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2017-08-21 21:41:14 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2017-08-21 21:41:14 +0000
commitc2cdcf41ccf92e65434001bc73d5d81b4c4210dd (patch)
treeb806cd4f2e6e8fcd9ec7d6f315a0aa469b48521d /usr.bin/tput
parente9d6f86c3468c07e6b1b12c0dd0b46516528e450 (diff)
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/tput')
-rw-r--r--usr.bin/tput/tput.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c
index 8289ad3d2f3..e3fa82c3812 100644
--- a/usr.bin/tput/tput.c
+++ b/usr.bin/tput/tput.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tput.c,v 1.22 2015/11/16 03:03:28 deraadt Exp $ */
+/* $OpenBSD: tput.c,v 1.23 2017/08/21 21:41:13 deraadt Exp $ */
/*
* Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -52,6 +52,7 @@
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
+#include <errno.h>
#include <limits.h>
#include <string.h>
@@ -269,9 +270,10 @@ init(void)
size_t len;
char *buf;
int wstatus;
+ pid_t pid;
if (init_prog && !issetugid()) {
- switch (vfork()) {
+ switch (pid = vfork()) {
case -1:
err(4, "vfork");
break;
@@ -281,7 +283,10 @@ init(void)
_exit(127);
break;
default:
- wait(&wstatus);
+ while (waitpid(pid, &wstatus, 0) == -1) {
+ if (errno != EINTR)
+ break;
+ }
/* parent */
break;
}