Home | History | Annotate | Download | only in sigset
      1 /*
      2  * Copyright (c) 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 the signal shall be ignored
      9  if the value of the dist parameter is SIG_IGN.
     10 
     11  How this program tests this assertion is by setting up a handler
     12  "myhandler" for SIGUSR1. Then another call to signal() is made about
     13  SIGUSR1, this time with SIG_IGN as the value of the func parameter.
     14  SIGUSR1 should be ignored now, so unless myhandler gets called when
     15  SIGUSR1 is raised, the test passes, otherwise returns failure.
     16 
     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 int handler_called = 0;
     27 
     28 void myhandler(int signo)
     29 {
     30 	printf("SIGUSR1 called. Inside handler\n");
     31 	handler_called = 1;
     32 }
     33 
     34 int main(void)
     35 {
     36 	struct sigaction act;
     37 	act.sa_flags = 0;
     38 	act.sa_handler = myhandler;
     39 	sigemptyset(&act.sa_mask);
     40 
     41 	if (sigaction(SIGUSR1, &act, 0) != 0) {
     42 		perror("Unexpected error while using sigaction()");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	if (sigset(SIGUSR1, SIG_IGN) != myhandler) {
     47 		perror("Unexpected error while using signal()");
     48 		return PTS_UNRESOLVED;
     49 	}
     50 
     51 	raise(SIGUSR1);
     52 
     53 	if (handler_called == 1) {
     54 		printf
     55 		    ("Test FAILED: handler was called even though default was expected\n");
     56 		return PTS_FAIL;
     57 	}
     58 	return PTS_PASS;
     59 }
     60