1 // SPDX-License-Identifier: GPL-2.0-or-later 2 // Copyright (c) 2009 FUJITSU LIMITED 3 // Author: Shi Weihua <[email protected]> 4 5 #include <sys/types.h> 6 #include <sys/wait.h> 7 #include <err.h> 8 #include <errno.h> 9 #include <signal.h> 10 #include <stdlib.h> 11 #include <unistd.h> 12 #include <stdio.h> 13 14 #define UNUSED __attribute__ ((unused)) 15 16 static int test_switch = 0; 17 sighandler(UNUSED int signo)18void sighandler(UNUSED int signo) 19 { 20 test_switch = !test_switch; 21 } 22 main(void)23int main(void) 24 { 25 sigset_t signalset; 26 struct sigaction sa; 27 pid_t pid; 28 int status; 29 int count = 0; 30 31 sa.sa_handler = sighandler; 32 if (sigemptyset(&sa.sa_mask) < 0) 33 err(1, "sigemptyset()"); 34 35 sa.sa_flags = 0; 36 if (sigaction(SIGUSR1, &sa, NULL) < 0) 37 err(1, "sigaction()"); 38 39 if (sigemptyset(&signalset) < 0) 40 err(1, "sigemptyset()"); 41 42 /* wait for the signal SIGUSR1 to start testing */ 43 sigsuspend(&signalset); 44 if (errno != EINTR) 45 err(1, "sigsuspend()"); 46 47 do { 48 count++; 49 pid = fork(); 50 if (pid == -1) 51 err(1, "fork()"); 52 else if (pid == 0) { 53 return 0; 54 } else { 55 wait(&status); 56 } 57 } while (test_switch); 58 59 return 0; 60 } 61