blob: cb95b11e541646bc0e96e392db2ba0420ea1b94b [file] [log] [blame]
robbiew0dc07652005-06-03 16:29:48 +00001/*
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
Garrett Cooper2c282152010-12-16 00:55:50 -08006 * of this license, see the COPYING file at the top level of this
robbiew0dc07652005-06-03 16:29:48 +00007 * source tree.
8
9 Test case for assertion #2 of the sigaction system call that shows
10 sigaction (when used with a non-null oact pointer) changes the action
11 for a signal.
12
13 Steps:
14 1. Call sigaction to set handler for SIGFPE to use handler1
15 2. Call sigaction again to set handler for SIGFPE to use handler2,
Garrett Cooper2c282152010-12-16 00:55:50 -080016 but this time use a non-null oarg and verify the sa_handler for
robbiew0dc07652005-06-03 16:29:48 +000017 oarg is set for handler1.
18*/
19
20#include <signal.h>
21#include <stdio.h>
22#include "posixtest.h"
23
24int handler_called = 0;
25
26void handler1(int signo)
27{
28}
29
30void handler2(int signo)
31{
32}
33
34int main()
35{
36 struct sigaction act;
37 struct sigaction oact;
Garrett Cooper2c282152010-12-16 00:55:50 -080038
robbiew0dc07652005-06-03 16:29:48 +000039 act.sa_handler = handler1;
40 act.sa_flags = 0;
41 sigemptyset(&act.sa_mask);
42 if (sigaction(SIGFPE, &act, 0) == -1) {
43 perror("Unexpected error while attempting to setup test "
44 "pre-conditions");
45 return PTS_UNRESOLVED;
46 }
Garrett Cooper2c282152010-12-16 00:55:50 -080047
robbiew0dc07652005-06-03 16:29:48 +000048 act.sa_handler = handler2;
49 sigemptyset(&act.sa_mask);
50 if (sigaction(SIGFPE, &act, &oact) == -1) {
51 perror("Unexpected error while attempting to setup test "
52 "pre-conditions");
53 return PTS_UNRESOLVED;
54 }
55
56 if (oact.sa_handler == handler1) {
57 printf("Test PASSED\n");
58 return PTS_PASS;
59 }
60
61 printf("Test Failed\n");
62 return PTS_FAIL;
Chris Dearmanec6edca2012-10-17 19:54:01 -070063}