summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2014-07-09 18:19:41 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2014-07-09 18:19:41 +0000
commitd427cb1a17400f4ae33fb597e90288a33ca7cb7d (patch)
treee481a0120c19f28ad0c04981e0cb3d2ffa2806fb /regress/lib
parentdeea3ffc14d628daeda3e8274cc95747d41b39e9 (diff)
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.
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libc/arc4random-fork/arc4random-fork.c17
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));