• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
3  * Copyright (c) 2013, Cyril Hrubis <chrubis@suse.cz>
4  *
5  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
6  * This file is licensed under the GPL license.  For the full content
7  * of this license, see the COPYING file at the top level of this
8  * source tree.
9  *
10  * Steps:
11  * 1. Set up a handler for signal SIGABRT, such that it is called if
12  *    signal is ever raised.
13  * 2. Call sighold on that SIGABRT.
14  * 3. Raise a SIGABRT and verify that the signal handler was not called.
15  *    Otherwise, the test exits with unresolved results.
16  * 4. Call sigrelse on SIGABRT.
17  * 5. Verify that the handler gets called this time.
18  */
19 
20 #include <signal.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include "posixtest.h"
24 
25 static int handler_called;
26 
handler(int signo)27 static void handler(int signo)
28 {
29 	handler_called = 1;
30 }
31 
main(void)32 int main(void)
33 {
34 	struct sigaction act;
35 
36 	act.sa_handler = handler;
37 	act.sa_flags = 0;
38 	sigemptyset(&act.sa_mask);
39 	if (sigaction(SIGABRT, &act, 0) == -1) {
40 		perror("Failed to set signal handler.");
41 		return PTS_UNRESOLVED;
42 	}
43 
44 	sighold(SIGABRT);
45 
46 	if (raise(SIGABRT) == -1) {
47 		perror("Failed to raise SIGABRT.");
48 		return PTS_UNRESOLVED;
49 	}
50 
51 	if (handler_called) {
52 		printf("UNRESOLVED. possible problem in sigrelse\n");
53 		return PTS_UNRESOLVED;
54 	}
55 
56 	if (sigrelse(SIGABRT) == -1) {
57 		printf("UNRESOLVED. possible problem in sigrelse\n");
58 		return PTS_UNRESOLVED;
59 	}
60 
61 	usleep(100000);
62 
63 	if (handler_called) {
64 		printf("Test PASSED: SIGABRT removed from signal mask\n");
65 		return PTS_PASS;
66 	}
67 	printf("Test FAILED\n");
68 	return PTS_FAIL;
69 }
70