• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 #include <pthread.h>
23 #include <stdio.h>
24 #include <signal.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include "posixtest.h"
28 
29 #define SIGTOTEST SIGABRT
30 
31 static int handler_called;
32 
handler()33 static void handler()
34 {
35 	printf("signal was called\n");
36 	handler_called = 1;
37 	return;
38 }
39 
a_thread_func()40 static void *a_thread_func()
41 {
42 	struct sigaction act;
43 	act.sa_flags = 0;
44 	act.sa_handler = handler;
45 	sigemptyset(&act.sa_mask);
46 	sigaction(SIGTOTEST, &act, 0);
47 	sighold(SIGTOTEST);
48 	sigpause(SIGTOTEST);
49 	return NULL;
50 }
51 
main(void)52 int main(void)
53 {
54 	pthread_t new_th;
55 
56 	if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
57 		perror("Error creating thread\n");
58 		return PTS_UNRESOLVED;
59 	}
60 
61 	sleep(1);
62 
63 	if (pthread_kill(new_th, SIGTOTEST) != 0) {
64 		printf("Test UNRESOLVED: Couldn't send signal to thread\n");
65 		return PTS_UNRESOLVED;
66 	}
67 
68 	sleep(1);
69 
70 	if (handler_called != 1) {
71 		printf("Test FAILED: signal wasn't removed from signal mask\n");
72 		return PTS_FAIL;
73 	}
74 
75 	printf("Test PASSED\n");
76 	return PTS_PASS;
77 }
78