Home | History | Annotate | Download | only in sigprocmask
      1 /*
      2 
      3  * Copyright (c) 2003, Intel Corporation. All rights reserved.
      4  * Created by:  salwan.searty 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  The resulting set shall be the union of the current set and the signal
     10  set pointed to by set, if the value of the argument how is SIG_BLOCK.
     11 
     12 */
     13 
     14 #include <signal.h>
     15 #include <stdio.h>
     16 #include "posixtest.h"
     17 
     18 int handler_called = 0;
     19 
     20 void handler(int signo)
     21 {
     22 	handler_called = 1;
     23 }
     24 
     25 int main(void)
     26 {
     27 	struct sigaction act;
     28 	sigset_t blocked_set1, blocked_set2, pending_set;
     29 	sigemptyset(&blocked_set1);
     30 	sigemptyset(&blocked_set2);
     31 	sigaddset(&blocked_set1, SIGABRT);
     32 	sigaddset(&blocked_set2, SIGUSR2);
     33 
     34 	act.sa_handler = handler;
     35 	act.sa_flags = 0;
     36 	sigemptyset(&act.sa_mask);
     37 
     38 	if (sigaction(SIGABRT, &act, 0) == -1) {
     39 		perror("Unexpected error while attempting to setup test "
     40 		       "pre-conditions");
     41 		return PTS_UNRESOLVED;
     42 	}
     43 
     44 	if (sigaction(SIGUSR2, &act, 0) == -1) {
     45 		perror("Unexpected error while attempting to setup test "
     46 		       "pre-conditions");
     47 		return PTS_UNRESOLVED;
     48 	}
     49 
     50 	if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) {
     51 		perror
     52 		    ("Unexpected error while attempting to use sigprocmask.\n");
     53 		return PTS_UNRESOLVED;
     54 	}
     55 
     56 	if (sigprocmask(SIG_BLOCK, &blocked_set2, NULL) == -1) {
     57 		perror
     58 		    ("Unexpected error while attempting to use sigprocmask.\n");
     59 		return PTS_UNRESOLVED;
     60 	}
     61 
     62 	if ((raise(SIGABRT) == -1) | (raise(SIGUSR2) == -1)) {
     63 		perror("Unexpected error while attempting to setup test "
     64 		       "pre-conditions");
     65 		return PTS_UNRESOLVED;
     66 	}
     67 
     68 	if (handler_called) {
     69 		printf("FAIL: Signal was not blocked\n");
     70 		return PTS_FAIL;
     71 	}
     72 
     73 	if (sigpending(&pending_set) == -1) {
     74 		perror("Unexpected error while attempting to use sigpending\n");
     75 		return PTS_UNRESOLVED;
     76 	}
     77 
     78 	if ((sigismember(&pending_set, SIGABRT) !=
     79 	     1) | (sigismember(&pending_set, SIGUSR2) != 1)) {
     80 		perror("FAIL: sigismember did not return 1\n");
     81 		return PTS_UNRESOLVED;
     82 	}
     83 
     84 	printf("Test PASSED: signal was added to the process's signal mask\n");
     85 	return PTS_PASS;
     86 }
     87