summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthew <>2014-07-09 18:19:40 +0000
committermatthew <>2014-07-09 18:19:40 +0000
commit4ad21b851b73c49f8a20a8b6bf3c423280cbcff4 (patch)
tree961e57320e0a1834f8b9051a00b0e7fea8609d02
parentbaa1f4435249dbfdf92daeecd3fd2f8b2ca2df3a (diff)
downloadopenbsd-4ad21b851b73c49f8a20a8b6bf3c423280cbcff4.tar.gz
openbsd-4ad21b851b73c49f8a20a8b6bf3c423280cbcff4.tar.bz2
openbsd-4ad21b851b73c49f8a20a8b6bf3c423280cbcff4.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--src/regress/lib/libc/arc4random-fork/arc4random-fork.c17
1 files changed, 12 insertions, 5 deletions
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 @@
19#include <assert.h> 19#include <assert.h>
20#include <err.h> 20#include <err.h>
21#include <errno.h> 21#include <errno.h>
22#include <signal.h>
22#include <stdlib.h> 23#include <stdlib.h>
23#include <string.h> 24#include <string.h>
24#include <unistd.h> 25#include <unistd.h>
@@ -73,13 +74,13 @@ usage()
73} 74}
74 75
75static pid_t 76static pid_t
76_waitpid(pid_t pid, int *stat_loc, int options) 77safewaitpid(pid_t pid, int *status, int options)
77{ 78{
78 pid_t ret; 79 pid_t ret;
79 do { 80 do {
80 ret = waitpid(pid, stat_loc, options); 81 ret = waitpid(pid, status, options);
81 } while (ret == -1 && errno == EINTR); 82 } while (ret == -1 && errno == EINTR);
82 return ret; 83 return (ret);
83} 84}
84 85
85int 86int
@@ -90,6 +91,12 @@ main(int argc, char *argv[])
90 pid_t pidone, pidtwo; 91 pid_t pidone, pidtwo;
91 size_t i, countone = 0, counttwo = 0, countkids = 0; 92 size_t i, countone = 0, counttwo = 0, countkids = 0;
92 93
94 /* Ensure SIGCHLD isn't set to SIG_IGN. */
95 const struct sigaction sa = {
96 .sa_handler = SIG_DFL,
97 };
98 CHECK_EQ(0, sigaction(SIGCHLD, &sa, NULL));
99
93 while ((opt = getopt(argc, argv, "bp")) != -1) { 100 while ((opt = getopt(argc, argv, "bp")) != -1) {
94 switch (opt) { 101 switch (opt) {
95 case 'b': 102 case 'b':
@@ -134,11 +141,11 @@ main(int argc, char *argv[])
134 141
135 fillbuf(bufparent); 142 fillbuf(bufparent);
136 143
137 CHECK_EQ(pidone, _waitpid(pidone, &status, 0)); 144 CHECK_EQ(pidone, safewaitpid(pidone, &status, 0));
138 CHECK(WIFEXITED(status)); 145 CHECK(WIFEXITED(status));
139 CHECK_EQ(0, WEXITSTATUS(status)); 146 CHECK_EQ(0, WEXITSTATUS(status));
140 147
141 CHECK_EQ(pidtwo, _waitpid(pidtwo, &status, 0)); 148 CHECK_EQ(pidtwo, safewaitpid(pidtwo, &status, 0));
142 CHECK(WIFEXITED(status)); 149 CHECK(WIFEXITED(status));
143 CHECK_EQ(0, WEXITSTATUS(status)); 150 CHECK_EQ(0, WEXITSTATUS(status));
144 151