• 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 <time.h>
23 #include <unistd.h>
24 #include "posixtest.h"
25 
26 static int handler_called;
27 
handler(int signo PTS_ATTRIBUTE_UNUSED)28 static void handler(int signo PTS_ATTRIBUTE_UNUSED)
29 {
30 	handler_called = 1;
31 }
32 
main(void)33 int main(void)
34 {
35 	struct sigaction act;
36 	struct timespec signal_wait_ts = {0, 100000000};
37 
38 	act.sa_handler = handler;
39 	act.sa_flags = 0;
40 	sigemptyset(&act.sa_mask);
41 	if (sigaction(SIGABRT, &act, 0) == -1) {
42 		perror("Failed to set signal handler.");
43 		return PTS_UNRESOLVED;
44 	}
45 
46 	sighold(SIGABRT);
47 
48 	if (raise(SIGABRT) == -1) {
49 		perror("Failed to raise SIGABRT.");
50 		return PTS_UNRESOLVED;
51 	}
52 
53 	if (handler_called) {
54 		printf("UNRESOLVED. possible problem in sigrelse\n");
55 		return PTS_UNRESOLVED;
56 	}
57 
58 	if (sigrelse(SIGABRT) == -1) {
59 		printf("UNRESOLVED. possible problem in sigrelse\n");
60 		return PTS_UNRESOLVED;
61 	}
62 
63 	nanosleep(&signal_wait_ts, NULL);
64 
65 	if (handler_called) {
66 		printf("Test PASSED: SIGABRT removed from signal mask\n");
67 		return PTS_PASS;
68 	}
69 	printf("Test FAILED\n");
70 	return PTS_FAIL;
71 }
72