Home | History | Annotate | Download | only in sigaction
      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
      6  * of this license, see the COPYING file at the top level of this
      7  * source tree.
      8 
      9   Test case for assertion #12 of the sigaction system call that verifies
     10   signal-catching functions are executed on the alternate stack if the
     11   SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the
     12   sigaction function call, and an alternate stack has been setup with
     13   sigaltstack().
     14 
     15   NOTE: This test case does not attempt to verify the proper operation
     16         of sigaltstack.
     17 */
     18 
     19 #define _XOPEN_SOURCE 600
     20 
     21 #include <signal.h>
     22 #include <stdio.h>
     23 #include <stdlib.h>
     24 #include "posixtest.h"
     25 
     26 stack_t alt_ss;
     27 
     28 void handler(int signo)
     29 {
     30 	stack_t ss;
     31 
     32 	printf("Caught SIGUSR2\n");
     33 
     34 	if (sigaltstack(NULL, &ss) == -1) {
     35 		perror("Unexpected error while attempting to setup test "
     36 		       "pre-conditions");
     37 		exit(-1);
     38 	}
     39 
     40 	if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) {
     41 		printf("Test FAILED\n");
     42 		exit(-1);
     43 	}
     44 }
     45 
     46 int main(void)
     47 {
     48 	struct sigaction act;
     49 
     50 	act.sa_handler = handler;
     51 	act.sa_flags = SA_ONSTACK;
     52 	sigemptyset(&act.sa_mask);
     53 	if (sigaction(SIGUSR2, &act, 0) == -1) {
     54 		perror("Unexpected error while attempting to setup test "
     55 		       "pre-conditions");
     56 		return PTS_UNRESOLVED;
     57 	}
     58 
     59 	if ((alt_ss.ss_sp = malloc(SIGSTKSZ)) == NULL) {
     60 		perror("Unexpected error while attempting to setup test "
     61 		       "pre-conditions");
     62 		return PTS_UNRESOLVED;
     63 	}
     64 	alt_ss.ss_size = SIGSTKSZ;
     65 	alt_ss.ss_flags = 0;
     66 
     67 	if (sigaltstack(&alt_ss, NULL) == -1) {
     68 		perror("Unexpected error while attempting to setup test "
     69 		       "pre-conditions");
     70 		return PTS_UNRESOLVED;
     71 	}
     72 
     73 	if (raise(SIGUSR2) == -1) {
     74 		perror("Unexpected error while attempting to setup test "
     75 		       "pre-conditions");
     76 		return PTS_UNRESOLVED;
     77 	}
     78 
     79 	printf("Test PASSED\n");
     80 	return PTS_PASS;
     81 }
     82