diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2017-08-21 21:41:14 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2017-08-21 21:41:14 +0000 |
commit | c2cdcf41ccf92e65434001bc73d5d81b4c4210dd (patch) | |
tree | b806cd4f2e6e8fcd9ec7d6f315a0aa469b48521d /usr.bin | |
parent | e9d6f86c3468c07e6b1b12c0dd0b46516528e450 (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')
-rw-r--r-- | usr.bin/calendar/io.c | 11 | ||||
-rw-r--r-- | usr.bin/m4/gnum4.c | 10 | ||||
-rw-r--r-- | usr.bin/passwd/pwd_check.c | 15 | ||||
-rw-r--r-- | usr.bin/sendbug/sendbug.c | 13 | ||||
-rw-r--r-- | usr.bin/tput/tput.c | 11 | ||||
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 11 |
6 files changed, 48 insertions, 23 deletions
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index 428565dfdae..8abe7996917 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.45 2017/08/10 14:26:31 tb Exp $ */ +/* $OpenBSD: io.c,v 1.46 2017/08/21 21:41:13 deraadt Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -385,6 +385,7 @@ closecal(FILE *fp) struct stat sbuf; int nread, pdes[2], status; char buf[1024]; + pid_t pid; if (!doall) return; @@ -394,7 +395,7 @@ closecal(FILE *fp) goto done; if (pipe(pdes) < 0) goto done; - switch (vfork()) { + switch ((pid = vfork())) { case -1: /* error */ (void)close(pdes[0]); (void)close(pdes[1]); @@ -421,8 +422,10 @@ closecal(FILE *fp) (void)write(pdes[1], buf, nread); (void)close(pdes[1]); done: (void)fclose(fp); - while (wait(&status) >= 0) - ; + while (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) + break; + } } diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c index 4280cb97339..1de66f2fa1b 100644 --- a/usr.bin/m4/gnum4.c +++ b/usr.bin/m4/gnum4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gnum4.c,v 1.51 2017/06/15 13:48:42 bcallah Exp $ */ +/* $OpenBSD: gnum4.c,v 1.52 2017/08/21 21:41:13 deraadt Exp $ */ /* * Copyright (c) 1999 Marc Espie @@ -630,7 +630,7 @@ void doesyscmd(const char *cmd) { int p[2]; - pid_t pid, cpid; + pid_t cpid; char *argv[4]; int cc; int status; @@ -668,8 +668,10 @@ doesyscmd(const char *cmd) } while (cc > 0 || (cc == -1 && errno == EINTR)); (void) close(p[0]); - while ((pid = wait(&status)) != cpid && pid >= 0) - continue; + while (waitpid(cpid, &status, 0) == -1) { + if (errno != EINTR) + break; + } pbstr(getstring()); } } diff --git a/usr.bin/passwd/pwd_check.c b/usr.bin/passwd/pwd_check.c index fcb3dfdeb41..cfdd1f65ed2 100644 --- a/usr.bin/passwd/pwd_check.c +++ b/usr.bin/passwd/pwd_check.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwd_check.c,v 1.15 2015/12/09 19:39:10 mmcc Exp $ */ +/* $OpenBSD: pwd_check.c,v 1.16 2017/08/21 21:41:13 deraadt Exp $ */ /* * Copyright 2000 Niels Provos <provos@citi.umich.edu> @@ -138,12 +138,14 @@ pwd_check(login_cap_t *lc, char *password) err(1, "pledge"); for (i = 0; i < sizeof(patterns) / sizeof(*patterns); i++) { + int ret; + if (regcomp(&rgx, patterns[i].match, patterns[i].flags) != 0) continue; - res = regexec(&rgx, password, 0, NULL, 0); + ret = regexec(&rgx, password, 0, NULL, 0); regfree(&rgx); - if (res == 0) { + if (ret == 0) { printf("%s\n", patterns[i].response); exit(1); } @@ -181,8 +183,11 @@ pwd_check(login_cap_t *lc, char *password) } /* get the return value from the child */ - wait(&child); - if (WIFEXITED(child) && WEXITSTATUS(child) == 0) { + while (waitpid(child, &res, 0) == -1) { + if (errno != EINTR) + break; + } + if (WIFEXITED(res) && WEXITSTATUS(res) == 0) { free(checker); return (1); } 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); 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; } diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 949835f6bf6..9d866825107 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xinstall.c,v 1.65 2016/05/13 17:51:15 jmc Exp $ */ +/* $OpenBSD: xinstall.c,v 1.66 2017/08/21 21:41:13 deraadt Exp $ */ /* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */ /* @@ -558,11 +558,12 @@ strip(char *to_name) { int serrno, status; char * volatile path_strip; + pid_t pid; if (issetugid() || (path_strip = getenv("STRIP")) == NULL) path_strip = _PATH_STRIP; - switch (vfork()) { + switch ((pid = vfork())) { case -1: serrno = errno; (void)unlink(to_name); @@ -572,7 +573,11 @@ strip(char *to_name) warn("%s", path_strip); _exit(1); default: - if (wait(&status) == -1 || !WIFEXITED(status)) + while (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) + break; + } + if (!WIFEXITED(status)) (void)unlink(to_name); } } |