1 /*
2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
3  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
4  * This file is licensed under the GPL license.  For the full content
5  * of this license, see the COPYING file at the top level of this
6  * source tree.
7 
8  This program verifies that sigpause() removes sig from the signal mask.
9 
10  Steps:
11  1. From the main() function, create a new thread. Give the new thread a
12     a second to set up for receiving a signal, and to suspend itself using
13     sigpause().
14  2. Have main() send the signal indicated by SIGTOTEST to the new thread,
15     using pthread_kill(). After doing this, give the new thread a second
16     to get to the signal handler.
17  3. In the main() thread, if the handler_called variable wasn't set to 1,
18     then the test has failed, else it passed.
19  */
20 
21 #define _XOPEN_SOURCE 600
22 
23 #include <pthread.h>
24 #include <stdio.h>
25 #include <signal.h>
26 #include <errno.h>
27 #include <unistd.h>
28 #include "posixtest.h"
29 
30 #define SIGTOTEST SIGABRT
31 
32 static int handler_called;
33 
handler()34 static void handler()
35 {
36 	printf("signal was called\n");
37 	handler_called = 1;
38 	return;
39 }
40 
a_thread_func()41 static void *a_thread_func()
42 {
43 	struct sigaction act;
44 	act.sa_flags = 0;
45 	act.sa_handler = handler;
46 	sigemptyset(&act.sa_mask);
47 	sigaction(SIGTOTEST, &act, 0);
48 	sighold(SIGTOTEST);
49 	sigpause(SIGTOTEST);
50 	return NULL;
51 }
52 
main(void)53 int main(void)
54 {
55 	pthread_t new_th;
56 
57 	if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
58 		perror("Error creating thread\n");
59 		return PTS_UNRESOLVED;
60 	}
61 
62 	sleep(1);
63 
64 	if (pthread_kill(new_th, SIGTOTEST) != 0) {
65 		printf("Test UNRESOLVED: Couldn't send signal to thread\n");
66 		return PTS_UNRESOLVED;
67 	}
68 
69 	sleep(1);
70 
71 	if (handler_called != 1) {
72 		printf("Test FAILED: signal wasn't removed from signal mask\n");
73 		return PTS_FAIL;
74 	}
75 
76 	printf("Test PASSED\n");
77 	return PTS_PASS;
78 }
79