Home | History | Annotate | Download | only in raise
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  julie.n.fleischer 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 that the the raise() function does not return until after the
      9  *  signal handler it calls returns.
     10  *  This test is only performed on one signal.  All other signals are
     11  *  considered to be in the same equivalence class.
     12  */
     13 
     14 #include <signal.h>
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 #include <sys/types.h>
     18 #include <unistd.h>
     19 #include "posixtest.h"
     20 
     21 #define SIGTOTEST SIGABRT
     22 
     23 /*
     24  * Copyright (c) 2002, Intel Corporation. All rights reserved.
     25  * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
     26  * This file is licensed under the GPL license.  For the full content
     27  * of this license, see the COPYING file at the top level of this
     28  * source tree.
     29 
     30  * Declare a global variable to keep track of where we were.
     31  */
     32 #define BEFOREHANDLER 1
     33 #define INHANDLER 2
     34 #define LEAVINGHANDLER 3
     35 int globalStatus = BEFOREHANDLER;
     36 
     37 void handler(int signo)
     38 {
     39 	globalStatus = INHANDLER;
     40 	printf("Caught signal being tested!\n");
     41 	printf("Sleeping...\n");
     42 	sleep(2);
     43 	globalStatus = LEAVINGHANDLER;
     44 }
     45 
     46 int main(void)
     47 {
     48 	struct sigaction act;
     49 
     50 	act.sa_handler = handler;
     51 	act.sa_flags = 0;
     52 	if (sigemptyset(&act.sa_mask) == -1) {
     53 		perror("Error calling sigemptyset\n");
     54 		return PTS_UNRESOLVED;
     55 	}
     56 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
     57 		perror("Error calling sigaction\n");
     58 		return PTS_UNRESOLVED;
     59 	}
     60 	if (raise(SIGTOTEST) != 0) {
     61 		printf("Could not raise signal being tested\n");
     62 		return PTS_FAIL;
     63 	}
     64 
     65 	if (INHANDLER == globalStatus || BEFOREHANDLER == globalStatus) {
     66 		printf("Test FAILED\n");
     67 		return PTS_FAIL;
     68 	}
     69 
     70 	if (LEAVINGHANDLER == globalStatus) {
     71 		printf("Test PASSED\n");
     72 		return PTS_PASS;
     73 	}
     74 
     75 	printf("Should not reach here\n");
     76 	return PTS_UNRESOLVED;
     77 }
     78