Home | History | Annotate | Download | only in sigtimedwait
      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 sigtimedwait() returns -1 upon unsuccessful completion.
      9 
     10     NOTE: This program has commented out areas. The commented out functionality
     11     sets a timer in case sigtimedwait() never returns, to help the program
     12     from hanging. To make this program
     13     runnable on a typical system, I've commented out the timer functionality
     14     by default. However, if you do have a timers implementation on your
     15     system, then it is recommened that you uncomment the timers-related lines
     16     of code in this program.
     17 
     18     Steps:
     19     1. Register signal TIMERSIGNAL with the handler myhandler
     20    (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait()
     21        never returns.
     22     3. Call sigtimedwait() to wait for non-pending signal SIGTOTEST for SIGTIMEDWAITSEC
     23        seconds.
     24     4. Verify that sigtimedwait() returns a -1.
     25  */
     26 
     27 #define _XOPEN_SOURCE 600
     28 #define _XOPEN_REALTIME 1
     29 
     30 #define TIMERSIGNAL SIGUSR1
     31 #define SIGTOTEST SIGUSR2
     32 #define TIMERSEC 2
     33 #define SIGTIMEDWAITSEC 0
     34 
     35 #include <signal.h>
     36 #include <stdio.h>
     37 #include <stdlib.h>
     38 #include <time.h>
     39 #include <unistd.h>
     40 #include <sys/wait.h>
     41 #include "posixtest.h"
     42 
     43 void myhandler(int signo)
     44 {
     45 	printf
     46 	    ("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n",
     47 	     TIMERSEC);
     48 	exit(PTS_FAIL);
     49 }
     50 
     51 int main(void)
     52 {
     53 	struct sigaction act;
     54 
     55 	sigset_t selectset;
     56 	struct timespec ts;
     57 /*
     58 	struct sigevent ev;
     59 	timer_t tid;
     60 	struct itimerspec its;
     61 
     62         its.it_interval.tv_sec = 0;
     63         its.it_interval.tv_nsec = 0;
     64         its.it_value.tv_sec = TIMERSEC;
     65         its.it_value.tv_nsec = 0;
     66 
     67         ev.sigev_notify = SIGEV_SIGNAL;
     68         ev.sigev_signo = TIMERSIGNAL;
     69 */
     70 	act.sa_flags = 0;
     71 	act.sa_handler = myhandler;
     72 	sigemptyset(&act.sa_mask);
     73 	sigaction(TIMERSIGNAL, &act, 0);
     74 
     75 	sigemptyset(&selectset);
     76 	sigaddset(&selectset, SIGTOTEST);
     77 
     78 	ts.tv_sec = SIGTIMEDWAITSEC;
     79 	ts.tv_nsec = 0;
     80 /*
     81         if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
     82                 perror("timer_create() did not return success\n");
     83                 return PTS_UNRESOLVED;
     84         }
     85 
     86         if (timer_settime(tid, 0, &its, NULL) != 0) {
     87                 perror("timer_settime() did not return success\n");
     88                 return PTS_UNRESOLVED;
     89         }
     90 */
     91 	if (sigtimedwait(&selectset, NULL, &ts) != -1) {
     92 		printf
     93 		    ("Test FAILED: sigtimedwait() did not return with an error\n");
     94 		return PTS_FAIL;
     95 	}
     96 
     97 	printf("Test PASSED\n");
     98 	return PTS_PASS;
     99 }
    100