From 4ad21b851b73c49f8a20a8b6bf3c423280cbcff4 Mon Sep 17 00:00:00 2001 From: matthew <> Date: Wed, 9 Jul 2014 18:19:40 +0000 Subject: 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. --- src/regress/lib/libc/arc4random-fork/arc4random-fork.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c b/src/regress/lib/libc/arc4random-fork/arc4random-fork.c index af617af625..7152e5a3e7 100644 --- a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c +++ b/src/regress/lib/libc/arc4random-fork/arc4random-fork.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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)); -- cgit v1.2.3-55-g6feb