Home | History | Annotate | Download | only in sigpending
      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 sigpending() function stores the set of signals that
      9  *  are blocked from delivery to a signal handler function.  Steps are:
     10  *  1)  Block three signals from delivery to a signal handler.
     11  *  2)  Raise the signal to get into that signal handler.
     12  *  From the signal handler:
     13  *    3)  Raise two of the blocked signals.
     14  *    4)  Verify that the two signals raised are shown via sigpending.
     15  *    5)  Verify the one signal not raised is not shown.
     16  */
     17 
     18 /*
     19  * Copyright (c) 2002, Intel Corporation. All rights reserved.
     20  * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
     21  * This file is licensed under the GPL license.  For the full content
     22  * of this license, see the COPYING file at the top level of this
     23  * source tree.
     24 
     25  *  The handler raises the two blocked signals and verifies they are
     26  *  shown via sigpending().
     27  *  It uses exit() to leave so that the signals are not executed.
     28  */
     29 
     30 #include <signal.h>
     31 #include <stdio.h>
     32 #include <stdlib.h>
     33 #include "posixtest.h"
     34 
     35 void handler(int signo)
     36 {
     37 	sigset_t pendingset;
     38 
     39 	if (sigemptyset(&pendingset) == -1) {
     40 		printf("Could not call sigemptyset()\n");
     41 		exit(-1);
     42 	}
     43 	if (raise(SIGCONT) != 0) {
     44 		printf("Could not raise SIGCONT\n");
     45 		exit(-1);
     46 	}
     47 	if (raise(SIGUSR1) != 0) {
     48 		printf("Could not raise SIGUSR1\n");
     49 		exit(-1);
     50 	}
     51 
     52 	if (sigpending(&pendingset) == -1) {
     53 		printf("Error calling sigpending()\n");
     54 		exit(-1);
     55 	}
     56 
     57 	if (sigismember(&pendingset, SIGCONT) == 1) {
     58 		if (sigismember(&pendingset, SIGUSR1) == 1) {
     59 			printf("All pending signals found\n");
     60 			if (sigismember(&pendingset, SIGHUP) == 0) {
     61 				printf("Unsent signals not found.\n");
     62 				printf("Test PASSED\n");
     63 				exit(0);
     64 			} else {
     65 				printf("Error with unsent signals\n");
     66 				printf("Test FAILED\n");
     67 				exit(-1);
     68 			}
     69 		} else {
     70 			printf("Not all pending signals found\n");
     71 			exit(-1);
     72 		}
     73 	} else {
     74 		printf("Not all pending signals found\n");
     75 		exit(-1);
     76 	}
     77 }
     78 
     79 int main(void)
     80 {
     81 	struct sigaction act;
     82 
     83 	act.sa_handler = handler;
     84 	act.sa_flags = 0;
     85 
     86 	if (sigemptyset(&act.sa_mask) == -1) {
     87 		printf("Could not call sigemptyset()\n");
     88 		return PTS_UNRESOLVED;
     89 	}
     90 
     91 	if ((sigaddset(&act.sa_mask, SIGCONT) == -1) ||
     92 	    (sigaddset(&act.sa_mask, SIGHUP) == -1) ||
     93 	    (sigaddset(&act.sa_mask, SIGUSR1) == -1)) {
     94 		perror("Error calling sigaddset()\n");
     95 		return PTS_UNRESOLVED;
     96 	}
     97 
     98 	if (sigaction(SIGTTOU, &act, 0) == -1) {
     99 		perror("Could not call sigaction()");
    100 		return PTS_UNRESOLVED;
    101 	}
    102 
    103 	if (raise(SIGTTOU) == -1) {
    104 		perror("Could not raise SIGTTOU");
    105 		return PTS_UNRESOLVED;
    106 	}
    107 	printf("This code should not be reachable\n");
    108 	return PTS_UNRESOLVED;
    109 }
    110