robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 6 | * of this license, see the COPYING file at the top level of this |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 7 | * 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 Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 16 | but this time use a non-null oarg and verify the sa_handler for |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 17 | oarg is set for handler1. |
| 18 | */ |
| 19 | |
| 20 | #include <signal.h> |
| 21 | #include <stdio.h> |
| 22 | #include "posixtest.h" |
| 23 | |
| 24 | int handler_called = 0; |
| 25 | |
| 26 | void handler1(int signo) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | void handler2(int signo) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | int main() |
| 35 | { |
| 36 | struct sigaction act; |
| 37 | struct sigaction oact; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 38 | |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 39 | 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 Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 47 | |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 48 | 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 Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame^] | 63 | } |