diff options
author | 2014-07-09 18:19:40 +0000 | |
---|---|---|
committer | 2014-07-09 18:19:40 +0000 | |
commit | 5a11c7edcb402aac4335bea16b9983964ed30282 (patch) | |
tree | 37e0ed9b33cb0007eefce3694390b4b0bffc5486 | |
parent | autoconf(9) is your friend and it knows you more than you think. It (diff) | |
download | wireguard-openbsd-5a11c7edcb402aac4335bea16b9983964ed30282.tar.xz wireguard-openbsd-5a11c7edcb402aac4335bea16b9983964ed30282.zip |
Minor cleanups
Rename _waitpid() to safewaitpid() to avoid POSIX reserved identifier
namespace.
KNF nit: return value expressions should be surrounded by parentheses,
per style(9).
Ensure SIGCHLD is set to SIG_DFL, not SIG_IGN. POSIX allows (and
requires under XSI) that terminated child processes not leave zombies
if SIGCHLD is set to SIG_IGN, and it also allows execve() to leave
SIGCHLD set to SIG_IGN.
-rw-r--r-- | regress/lib/libc/arc4random-fork/arc4random-fork.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/regress/lib/libc/arc4random-fork/arc4random-fork.c b/regress/lib/libc/arc4random-fork/arc4random-fork.c index af617af6251..7152e5a3e75 100644 --- a/regress/lib/libc/arc4random-fork/arc4random-fork.c +++ b/regress/lib/libc/arc4random-fork/arc4random-fork.c @@ -19,6 +19,7 @@ #include <assert.h> #include <err.h> #include <errno.h> +#include <signal.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -73,13 +74,13 @@ usage() } static pid_t -_waitpid(pid_t pid, int *stat_loc, int options) +safewaitpid(pid_t pid, int *status, int options) { pid_t ret; do { - ret = waitpid(pid, stat_loc, options); + ret = waitpid(pid, status, options); } while (ret == -1 && errno == EINTR); - return ret; + return (ret); } int @@ -90,6 +91,12 @@ main(int argc, char *argv[]) pid_t pidone, pidtwo; size_t i, countone = 0, counttwo = 0, countkids = 0; + /* Ensure SIGCHLD isn't set to SIG_IGN. */ + const struct sigaction sa = { + .sa_handler = SIG_DFL, + }; + CHECK_EQ(0, sigaction(SIGCHLD, &sa, NULL)); + while ((opt = getopt(argc, argv, "bp")) != -1) { switch (opt) { case 'b': @@ -134,11 +141,11 @@ main(int argc, char *argv[]) fillbuf(bufparent); - CHECK_EQ(pidone, _waitpid(pidone, &status, 0)); + CHECK_EQ(pidone, safewaitpid(pidone, &status, 0)); CHECK(WIFEXITED(status)); CHECK_EQ(0, WEXITSTATUS(status)); - CHECK_EQ(pidtwo, _waitpid(pidtwo, &status, 0)); + CHECK_EQ(pidtwo, safewaitpid(pidtwo, &status, 0)); CHECK(WIFEXITED(status)); CHECK_EQ(0, WEXITSTATUS(status)); |