]>
git.saurik.com Git - apple/xnu.git/blob - tests/sigchld_return.c
7 #include <darwintest.h>
10 static int exitcode
= 0x6789BEEF;
13 void handler (int sig
, siginfo_t
*sip
, __unused
void *uconp
)
15 /* Should handle the SIGCHLD signal */
16 T_ASSERT_EQ_INT(sig
, SIGCHLD
, "Captured signal returns 0x%x, expected SIGCHLD (0x%x).", sig
, SIGCHLD
);
17 T_QUIET
; T_ASSERT_NOTNULL(sip
, "siginfo_t returned NULL but should have returned data.");
18 T_ASSERT_EQ_INT(sip
->si_code
, CLD_EXITED
, "si_code returns 0x%x, expected CLD_EXITED (0x%x).", sip
->si_code
, CLD_EXITED
);
19 T_ASSERT_EQ_INT(sip
->si_status
, exitcode
, "si_status returns 0x%08X, expected the child's exit code (0x%08X).", sip
->si_status
, exitcode
);
24 T_DECL(sigchldreturn
, "checks that a child process exited with an exitcode returns correctly to parent", T_META_CHECK_LEAKS(false))
29 act
.sa_sigaction
= handler
;
30 act
.sa_flags
= SA_SIGINFO
;
32 /* Set action for signal */
33 T_QUIET
; T_ASSERT_POSIX_SUCCESS(sigaction (SIGCHLD
, &act
, NULL
), "Calling sigaction() failed for SIGCHLD");
35 /* Now fork a child that just exits */
37 T_QUIET
; T_ASSERT_NE_INT(pid
, -1, "fork() failed!");
44 /* Main program that did the fork */
45 /* We should process the signal, then exit */
46 while (!should_exit
) {