1 /* 2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. 3 * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 Test case for assertion #1 of the sigaction system call that shows 9 sigaction (when used with a non-null act pointer) changes the action 10 for a signal. 11 12 Steps: 13 1. Initialize a global variable to indicate the signal 14 handler has not been called. (A signal handler of the 15 prototype "void func(int signo);" will set the global 16 variable to indicate otherwise. 17 2. Use sigaction to setup a signal handler for SIGUSR2 18 3. Raise SIGUSR2. 19 4. Verify the global indicates the signal was called. 20 */ 21 22 #include <signal.h> 23 #include <stdio.h> 24 #include "posixtest.h" 25 26 static volatile int handler_called; 27 handler(int signo LTP_ATTRIBUTE_UNUSED)28void handler(int signo LTP_ATTRIBUTE_UNUSED) 29 { 30 handler_called = 1; 31 } 32 main(void)33int main(void) 34 { 35 36 struct sigaction act; 37 38 act.sa_handler = handler; 39 act.sa_flags = 0; 40 sigemptyset(&act.sa_mask); 41 if (sigaction(SIGUSR2, &act, 0) == -1) { 42 perror("Unexpected error while attempting to setup test " 43 "pre-conditions"); 44 return PTS_UNRESOLVED; 45 } 46 47 if (raise(SIGUSR2) == -1) { 48 perror("Unexpected error while attempting to setup test " 49 "pre-conditions"); 50 return PTS_UNRESOLVED; 51 } 52 53 if (handler_called) { 54 printf("Test PASSED\n"); 55 return PTS_PASS; 56 } 57 58 printf("Test FAILED\n"); 59 return PTS_FAIL; 60 } 61