Home | History | Annotate | Download | only in sigqueue
      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  This program verifies that if the value of pid causes signo to be
      9  generated for the sending process, and if signo is not blocked for
     10  the calling thread and if no other thread has signo unblocked or is
     11  waiting in a sigwait() function for signo, then signal SIGTOTEST
     12  is delivered to the calling thread before the sigqueue() function returns.
     13 
     14  Steps:
     15  - Register for myhandler to be called when SIGTOTEST is called, and make
     16    sure SA_SIGINFO is set.
     17  - Using sigqueue(), send SIGTOTEST to the current process.
     18  - Inside handler, verify that the global return_val variable has not been
     19    set yet to the return value of sigqueue. If it has, then that means that
     20    sigqueu has returned before the handler finished executing, and thus is
     21    a FAILED test.
     22  - Also before the program ends, verify that the handler
     23    has been called.
     24  */
     25 
     26 #define _XOPEN_SOURCE 600
     27 #define _XOPEN_REALTIME 1
     28 #define SIGTOTEST SIGRTMIN
     29 #define NUMCALLS 5
     30 
     31 #include <signal.h>
     32 #include <stdio.h>
     33 #include <unistd.h>
     34 #include <stdlib.h>
     35 #include <errno.h>
     36 #include "posixtest.h"
     37 
     38 int return_val = 1;
     39 int handler_called = 0;
     40 
     41 void myhandler(int signo, siginfo_t * info, void *context)
     42 {
     43 	handler_called = 1;
     44 	if (return_val != 1) {
     45 		printf
     46 		    ("Test FAILED: sigqueue() seems to have returned before handler finished executing.\n");
     47 		exit(1);
     48 	}
     49 }
     50 
     51 int main(void)
     52 {
     53 	int pid;
     54 	union sigval value;
     55 	struct sigaction act;
     56 
     57 	act.sa_flags = SA_SIGINFO;
     58 	act.sa_sigaction = myhandler;
     59 	sigemptyset(&act.sa_mask);
     60 	sigaction(SIGTOTEST, &act, 0);
     61 
     62 	value.sival_int = 0;	/* 0 is just an arbitrary value */
     63 	pid = getpid();
     64 
     65 	if ((return_val = sigqueue(pid, SIGTOTEST, value)) != 0) {
     66 		printf
     67 		    ("Test UNRESOLVED: call to sigqueue did not return success\n");
     68 		return PTS_UNRESOLVED;
     69 	}
     70 
     71 	if (handler_called != 1) {
     72 		printf("Test FAILED: signal was not delivered to process\n");
     73 		return PTS_FAIL;
     74 	}
     75 	return PTS_PASS;
     76 }
     77