Home | History | Annotate | Download | only in sigaction
      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 SIGVTALRM
     18   3. Raise SIGVTALRM.
     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 int handler_called = 0;
     27 
     28 void handler(int signo)
     29 {
     30 	handler_called = 1;
     31 }
     32 
     33 int main(void)
     34 {
     35 	struct sigaction act;
     36 
     37 	act.sa_handler = handler;
     38 	act.sa_flags = 0;
     39 	sigemptyset(&act.sa_mask);
     40 	if (sigaction(SIGVTALRM, &act, 0) == -1) {
     41 		perror("Unexpected error while attempting to setup test "
     42 		       "pre-conditions");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	if (raise(SIGVTALRM) == -1) {
     47 		perror("Unexpected error while attempting to setup test "
     48 		       "pre-conditions");
     49 		return PTS_UNRESOLVED;
     50 	}
     51 
     52 	if (handler_called) {
     53 		printf("Test PASSED\n");
     54 		return PTS_PASS;
     55 	}
     56 
     57 	printf("Test FAILED\n");
     58 	return PTS_FAIL;
     59 }
     60