1 // commit: 370f78f2c80c64b7b0780a01e672494a26b5678e 2011-03-09
2 // raise should be robust against forking from a signal handler
11 static volatile int c0;
12 static volatile int c1;
13 static volatile int child;
15 static void handler0(int sig)
20 static void handler1(int sig)
24 case 0: child=1; break;
25 case -1: t_error("fork failed: %s\n", strerror(errno));
29 static void *start(void *arg)
33 for (i = 0; i < 1000; i++) {
36 t_error("raise failed: %s\n", strerror(errno));
39 t_error("lost signals: got %d, wanted 1000 (ischild %d forks %d)\n", c0, child, c1);
43 /* make sure we got all pthread_kills, then wait the forked children */
45 for (i = 0; i < 100; i++) {
48 t_error("wait failed: %s\n", strerror(errno));
49 else if (!WIFEXITED(s) || WTERMSIG(s))
50 t_error("child failed: pid:%d status:%d\n", r, s);
61 if (signal(SIGRTMIN, handler0) == SIG_ERR)
62 t_error("registering signal handler failed: %s\n", strerror(errno));
63 if (signal(SIGRTMIN+1, handler1) == SIG_ERR)
64 t_error("registering signal handler failed: %s\n", strerror(errno));
66 r = pthread_create(&t, 0, start, 0);
68 t_error("pthread_create failed: %s\n", strerror(r));
69 for (i = 0; i < 100; i++) {
70 r = pthread_kill(t, SIGRTMIN+1);
72 t_error("phread_kill failed: %s\n", strerror(r));
74 r = pthread_join(t,&p);
76 t_error("pthread_join failed: %s\n", strerror(r));