Home | History | Annotate | Download | only in sigaltstack
      1 /*
      2  * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
      3  * Created by:  salwan.searty 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  This program tests the assertion that sigaltstack() returns 0 upon
      9  successful completion.
     10 */
     11 
     12 #define _XOPEN_SOURCE 600
     13 
     14 #include <signal.h>
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 #include "posixtest.h"
     18 
     19 #define SIGTOTEST SIGUSR1
     20 
     21 stack_t alternate_s;
     22 
     23 void handler()
     24 {
     25 	printf("Just a dummy handler\n");
     26 }
     27 
     28 int main(void)
     29 {
     30 
     31 	struct sigaction act;
     32 	act.sa_flags = SA_ONSTACK;
     33 	act.sa_handler = handler;
     34 	sigemptyset(&act.sa_mask);
     35 
     36 	if (sigaction(SIGUSR1, &act, 0) == -1) {
     37 		perror
     38 		    ("Unexpected error while attempting to setup test pre-conditions");
     39 		return PTS_UNRESOLVED;
     40 	}
     41 
     42 	if ((alternate_s.ss_sp = malloc(SIGSTKSZ)) == NULL) {
     43 		perror
     44 		    ("Unexpected error while attempting to setup test pre-conditions");
     45 		return PTS_UNRESOLVED;
     46 	}
     47 
     48 	alternate_s.ss_flags = 0;
     49 	alternate_s.ss_size = SIGSTKSZ;
     50 
     51 	if (sigaltstack(&alternate_s, NULL) != 0) {
     52 		printf("Test FAILED: sigaltstack didn't return 0.\n");
     53 		return PTS_FAIL;
     54 	}
     55 
     56 	printf("Test PASSED\n");
     57 	return PTS_PASS;
     58 }
     59