• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 tests the assertion that if SA_SIGINFO is set, then the
9  signal shall be queued to the receiving process.
10 
11  Steps:
12  - Register for myhandler to be called when SIGTOTEST is called, and make
13    sure SA_SIGINFO is set.
14  - Block signal SIGTOTEST from the process.
15  - Using sigqueue(), send NUMCALLS instances of SIGTOTEST to the current
16    process.
17  - Verify that the handler is executed NUMCALLS times AFTER SIGTOTEST
18    is unblocked.
19  */
20 
21 #define _XOPEN_SOURCE 600
22 #define _XOPEN_REALTIME 1
23 #define SIGTOTEST SIGRTMIN
24 #define NUMCALLS 5
25 
26 #include <signal.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include "posixtest.h"
32 
33 int counter = 0;
34 
myhandler(int signo,siginfo_t * info,void * context)35 void myhandler(int signo, siginfo_t * info, void *context)
36 {
37 	counter++;
38 }
39 
main(void)40 int main(void)
41 {
42 	int pid, i;
43 	union sigval value;
44 	struct sigaction act;
45 
46 	act.sa_flags = SA_SIGINFO;
47 	act.sa_sigaction = myhandler;
48 	sigemptyset(&act.sa_mask);
49 	sigaction(SIGTOTEST, &act, 0);
50 
51 	pid = getpid();
52 
53 	sighold(SIGTOTEST);
54 
55 	for (i = 0; i < NUMCALLS; i++) {
56 		value.sival_int = i;	/* i is just an arbitrary value */
57 		if (sigqueue(pid, SIGTOTEST, value) != 0) {
58 			printf
59 			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
60 			return PTS_UNRESOLVED;
61 		}
62 	}
63 
64 	if (0 != counter) {
65 		printf
66 		    ("Test UNRESOLVED: handler called even though %d has not been removed from the signal mask\n",
67 		     SIGTOTEST);
68 		return PTS_UNRESOLVED;
69 	}
70 
71 	sigrelse(SIGTOTEST);
72 
73 	if (NUMCALLS != counter) {
74 		printf
75 		    ("Test FAILED: %d was queued %d time(s) even though sigqueue was called %d time(s) for %d\n",
76 		     SIGTOTEST, counter, NUMCALLS, SIGTOTEST);
77 		return PTS_FAIL;
78 	}
79 	return PTS_PASS;
80 }
81