• 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 #3 of the sigaction system call that shows
10   calling sigaction with a null act argument does not change the
11   signal handler.
12 
13   Steps:
14   1. Initialize global variable to indicate handler has not been called
15   2. Set the signal handler for SIGPIPE to handler
16   3. Call sigaction with a null act
17   4. raise SIGPIPE
18   5. Verify handler was called.
19 */
20 
21 #include <signal.h>
22 #include <stdio.h>
23 #include "posixtest.h"
24 
25 static volatile int handler_called;
26 
handler(int signo LTP_ATTRIBUTE_UNUSED)27 void handler(int signo LTP_ATTRIBUTE_UNUSED)
28 {
29 	handler_called = 1;
30 }
31 
main(void)32 int main(void)
33 {
34 	struct sigaction act;
35 	struct sigaction oact;
36 
37 	act.sa_handler = handler;
38 	act.sa_flags = 0;
39 	sigemptyset(&act.sa_mask);
40 	if (sigaction(SIGPIPE, &act, 0) == -1) {
41 		perror("Unexpected error while attempting to setup test "
42 		       "pre-conditions");
43 		return PTS_UNRESOLVED;
44 	}
45 
46 	if (sigaction(SIGPIPE, 0, &oact) == -1) {
47 		perror("Unexpected error while attempting to setup test "
48 		       "pre-conditions");
49 		return PTS_UNRESOLVED;
50 	}
51 
52 	if (raise(SIGPIPE) == -1) {
53 		perror("Unexpected error while attempting to setup test "
54 		       "pre-conditions");
55 		return PTS_UNRESOLVED;
56 	}
57 
58 	if (handler_called) {
59 		printf("Test PASSED\n");
60 		return PTS_PASS;
61 	}
62 
63 	printf("Test FAILED\n");
64 	return PTS_FAIL;
65 }
66