mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
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
This commit is contained in:
parent
6248d27527
commit
2aeb6b04aa
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: fuse.c,v 1.28 2016/05/24 19:24:46 okan Exp $ */
|
||||
/* $OpenBSD: fuse.c,v 1.29 2017/08/21 21:41:13 deraadt Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
|
||||
*
|
||||
@ -294,7 +294,7 @@ ifuse_get_signal(unused int num)
|
||||
child = fork();
|
||||
|
||||
if (child < 0)
|
||||
return ;
|
||||
return;
|
||||
|
||||
f = sigse->args;
|
||||
if (child == 0) {
|
||||
@ -304,7 +304,10 @@ ifuse_get_signal(unused int num)
|
||||
}
|
||||
|
||||
fuse_loop(f);
|
||||
wait(&status);
|
||||
while (waitpid(child, &status, 0) == -1) {
|
||||
if (errno != EINTR)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: radiusd_bsdauth.c,v 1.7 2015/12/05 13:22:32 claudio Exp $ */
|
||||
/* $OpenBSD: radiusd_bsdauth.c,v 1.8 2017/08/21 21:41:13 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
|
||||
@ -61,7 +61,7 @@ struct auth_groupcheck_args {
|
||||
size_t grouplen;
|
||||
};
|
||||
|
||||
static void module_bsdauth_main(int, int);
|
||||
static pid_t module_bsdauth_main(int, int);
|
||||
static void module_bsdauth_config_set(void *, const char *, int,
|
||||
char * const *);
|
||||
static void module_bsdauth_userpass(void *, u_int, const char *,
|
||||
@ -82,12 +82,13 @@ main(int argc, char *argv[])
|
||||
struct imsg imsg;
|
||||
ssize_t n;
|
||||
size_t datalen;
|
||||
pid_t pid;
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pairsock) == -1)
|
||||
err(EXIT_FAILURE, "socketpair");
|
||||
|
||||
pipe_chld = pairsock[1];
|
||||
module_bsdauth_main(pairsock[0], pairsock[1]);
|
||||
pid = module_bsdauth_main(pairsock[0], pairsock[1]);
|
||||
|
||||
/*
|
||||
* Privileged process
|
||||
@ -201,12 +202,15 @@ group_done:
|
||||
imsg_flush(&ibuf);
|
||||
}
|
||||
imsg_clear(&ibuf);
|
||||
wait(&status);
|
||||
|
||||
while (waitpid(pid, &status, 0) == -1) {
|
||||
if (errno != EINTR)
|
||||
break;
|
||||
}
|
||||
exit(WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
static void
|
||||
static pid_t
|
||||
module_bsdauth_main(int pipe_prnt, int pipe_chld)
|
||||
{
|
||||
int i;
|
||||
@ -219,7 +223,7 @@ module_bsdauth_main(int pipe_prnt, int pipe_chld)
|
||||
|
||||
if (pid > 0) {
|
||||
close(pipe_prnt);
|
||||
return;
|
||||
return (pid);
|
||||
}
|
||||
close(pipe_chld);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user