Home | History | Annotate | Download | only in sigwaitinfo
      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  *  Test that the sigwaitinfo() function shall select the pending signal
      9     from the set set, and atomically clear it from the system's set of
     10     pending signals.
     11 
     12     Steps:
     13     1. Register signal SIGTOTEST with the handler myhandler
     14     2. Block SIGTOTEST from the process
     15     3. Raise the signal, causing it to be pending
     16     4. Call sigwaitinfo() and verify that the signal is no longer pending.
     17  */
     18 
     19 #define _XOPEN_SOURCE 600
     20 #define _XOPEN_REALTIME 1
     21 #define SIGTOTEST SIGUSR1
     22 
     23 #include <signal.h>
     24 #include <stdio.h>
     25 #include <stdlib.h>
     26 #include <unistd.h>
     27 #include <sys/wait.h>
     28 #include "posixtest.h"
     29 
     30 void myhandler(int signo)
     31 {
     32 	printf("Inside handler\n");
     33 }
     34 
     35 int main(void)
     36 {
     37 
     38 	struct sigaction act;
     39 	sigset_t pendingset, selectset;
     40 
     41 	act.sa_flags = 0;
     42 	act.sa_handler = myhandler;
     43 
     44 	sigemptyset(&pendingset);
     45 	sigemptyset(&selectset);
     46 	sigaddset(&selectset, SIGTOTEST);
     47 	sigemptyset(&act.sa_mask);
     48 
     49 	sigaction(SIGTOTEST, &act, 0);
     50 	sighold(SIGTOTEST);
     51 	raise(SIGTOTEST);
     52 
     53 	sigpending(&pendingset);
     54 
     55 	if (sigismember(&pendingset, SIGTOTEST) != 1) {
     56 		perror("SIGTOTEST is not pending\n");
     57 		return PTS_UNRESOLVED;
     58 	}
     59 
     60 	if (sigwaitinfo(&selectset, NULL) == -1) {
     61 		perror("Call to sigwaitinfo() failed\n");
     62 		return PTS_UNRESOLVED;
     63 	}
     64 
     65 	sigemptyset(&pendingset);
     66 	sigpending(&pendingset);
     67 
     68 	if (sigismember(&pendingset, SIGTOTEST) != 0) {
     69 		printf
     70 		    ("Test FAILED: Signal %d still pending even after call to sigwaitinfo()\n",
     71 		     SIGTOTEST);
     72 		return PTS_FAIL;
     73 	}
     74 
     75 	printf("Test PASSED\n");
     76 	return PTS_PASS;
     77 }
     78