1 /*
2   Test assertion #21 by verifying that adding a sigaction for SIGCHLD
3   with the SA_NOCLDWAIT bit set in sigaction.sa_flags will result in
4   a child process not transforming into a zombie after death.
5 */
6 
7 
8 #include <signal.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/wait.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include "posixtest.h"
15 
handler(int signo)16 void handler(int signo)
17 {
18 	printf("Caught SIGCHLD\n");
19 }
20 
main(void)21 int main(void)
22 {
23 
24 	/* Make sure this flag is supported. */
25 #ifndef SA_NOCLDWAIT
26 	fprintf(stderr, "SA_NOCLWAIT flag is not available for testing\n");
27 	return PTS_UNSUPPORTED;
28 #endif
29 
30 	struct sigaction act;
31 
32 	act.sa_handler = handler;
33 	act.sa_flags = SA_NOCLDWAIT;
34 	sigemptyset(&act.sa_mask);
35 	sigaction(SIGCHLD, &act, 0);
36 
37 	if (fork() == 0) {
38 		/* child */
39 		return 0;
40 	} else {
41 		/* parent */
42 		int s;
43 		if (wait(&s) == -1 && errno == ECHILD) {
44 			printf("Test PASSED\n");
45 			return PTS_PASS;
46 		}
47 	}
48 
49 	printf("Test FAILED\n");
50 	return PTS_FAIL;
51 }
52