• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2005, Bull S.A..  All rights reserved.
3 * Created by: Sebastien Decugis
4 * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * This sample test aims to check the following assertions:
19 *
20 * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal
21 * handling function.
22 *
23 * The steps are:
24 * -> register a handler for SIGUSR2 without SA_SIGINFO, and a known function
25 *   as sa_handler
26 * -> raise SIGUSR2, and check the function has been called.
27 *
28 * The test fails if the function is not called
29 */
30 
31 /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
32 #define _POSIX_C_SOURCE 200112L
33 
34 #include <pthread.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
40 
41 #include <signal.h>
42 #include <errno.h>
43 
44 #include "posixtest.h"
45 
46 static volatile sig_atomic_t called = 0;
47 
handler()48 static void handler()
49 {
50 	called = 1;
51 }
52 
main(void)53 int main(void)
54 {
55 	int ret;
56 	struct sigaction sa;
57 
58 	/* Set the signal handler */
59 	sa.sa_flags = 0;
60 	sa.sa_handler = handler;
61 	ret = sigemptyset(&sa.sa_mask);
62 
63 	if (ret != 0) {
64 		perror("Failed to empty signal set");
65 		return PTS_UNRESOLVED;
66 	}
67 
68 	/* Install the signal handler for SIGUSR2 */
69 	ret = sigaction(SIGUSR2, &sa, 0);
70 
71 	if (ret != 0) {
72 		perror("Failed to set signal handler");
73 		return PTS_UNRESOLVED;
74 	}
75 
76 	if (called) {
77 		fprintf(stderr,
78 			"The signal handler has been called before signal was raised");
79 		return PTS_FAIL;
80 	}
81 
82 	ret = raise(SIGUSR2);
83 
84 	if (ret != 0) {
85 		perror("Failed to raise SIGUSR2");
86 		return PTS_UNRESOLVED;
87 	}
88 
89 	if (!called) {
90 		fprintf(stderr, "The sa_handler was not called\n");
91 		return PTS_FAIL;
92 	}
93 
94 	printf("Test PASSED\n");
95 
96 	return PTS_PASS;
97 }
98