lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdlib.h> |
| 2 | #include <string.h> |
| 3 | #include <errno.h> |
| 4 | #include <stdio.h> |
| 5 | #include <sys/signal.h> |
| 6 | #include <sys/wait.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | |
| 10 | #ifdef __ARCH_USE_MMU__ |
| 11 | |
| 12 | static void test_handler(int signo) |
| 13 | { |
| 14 | write(1, "caught SIGCHLD\n", 15); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | int main(void) |
| 19 | { |
| 20 | pid_t mypid; |
| 21 | struct sigaction siga; |
| 22 | static sigset_t set; |
| 23 | |
| 24 | /* Set up sighandling */ |
| 25 | sigfillset(&set); |
| 26 | siga.sa_handler = test_handler; |
| 27 | siga.sa_mask = set; |
| 28 | siga.sa_flags = 0; |
| 29 | if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) { |
| 30 | fprintf(stderr, "sigaction choked: %s!", strerror(errno)); |
| 31 | exit(EXIT_FAILURE); |
| 32 | } |
| 33 | |
| 34 | /* Setup a child process to exercise the sig handling for us */ |
| 35 | mypid = getpid(); |
| 36 | if (fork() == 0) { |
| 37 | int i; |
| 38 | |
| 39 | for (i=0; i < 3; i++) { |
| 40 | sleep(2); |
| 41 | kill(mypid, SIGCHLD); |
| 42 | } |
| 43 | _exit(EXIT_SUCCESS); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /* Wait for signals */ |
| 48 | write(1, "waiting for a SIGCHLD\n",22); |
| 49 | for(;;) { |
| 50 | sleep(10); |
| 51 | if (waitpid(-1, NULL, WNOHANG | WUNTRACED) > 0) |
| 52 | break; |
| 53 | write(1, "after sleep\n", 12); |
| 54 | } |
| 55 | |
| 56 | printf("Bye-bye! All done!\n"); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | #else |
| 61 | |
| 62 | int main(void) |
| 63 | { |
| 64 | printf("Skipping test on non-mmu host!\n"); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | #endif |