• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 
3  * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
4  * Created by:  rusty.lynch REMOVE-THIS AT intel DOT com
5  * This file is licensed under the GPL license.  For the full content
6  * of this license, see the COPYING file at the top level of this
7  * source tree.
8 
9   Test case for assertion #12 of the sigaction system call that verifies
10   signal-catching functions are executed on the current stack if the
11   SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the
12   sigaction function call, but a new stack has not be set by sigaltstack().
13 
14   NOTE: This test case does not attempt to verify the proper operation
15         of sigaltstack.
16 */
17 #define _XOPEN_SOURCE 600
18 
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "posixtest.h"
23 
24 stack_t current;
25 
handler(int signo)26 void handler(int signo)
27 {
28 	stack_t oss;
29 
30 	printf("Caught SIGPIPE\n");
31 
32 	if (sigaltstack(NULL, &oss) == -1) {
33 		perror("Unexpected error while attempting to setup test "
34 		       "pre-conditions");
35 		exit(-1);
36 	}
37 
38 	if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) {
39 		printf("Test FAILED\n");
40 		exit(-1);
41 	}
42 }
43 
main(void)44 int main(void)
45 {
46 	struct sigaction act;
47 
48 	act.sa_handler = handler;
49 	act.sa_flags = SA_ONSTACK;
50 	sigemptyset(&act.sa_mask);
51 	if (sigaction(SIGPIPE, &act, 0) == -1) {
52 		perror("Unexpected error while attempting to setup test "
53 		       "pre-conditions");
54 		return PTS_UNRESOLVED;
55 	}
56 
57 	if (sigaltstack(NULL, &current) == -1) {
58 		perror("Unexpected error while attempting to setup test "
59 		       "pre-conditions");
60 		return PTS_UNRESOLVED;
61 	}
62 
63 	if (raise(SIGPIPE) == -1) {
64 		perror("Unexpected error while attempting to setup test "
65 		       "pre-conditions");
66 		return PTS_UNRESOLVED;
67 	}
68 
69 	printf("Test PASSED\n");
70 	return PTS_PASS;
71 }
72