• 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_REALTIME 1
22 #define SIGTOTEST SIGRTMIN
23 #define NUMCALLS 5
24 
25 #include <signal.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include "posixtest.h"
31 
32 static volatile int counter;
33 
myhandler(int signo LTP_ATTRIBUTE_UNUSED,siginfo_t * info LTP_ATTRIBUTE_UNUSED,void * context LTP_ATTRIBUTE_UNUSED)34 void myhandler(int signo LTP_ATTRIBUTE_UNUSED,
35 	siginfo_t *info LTP_ATTRIBUTE_UNUSED,
36 	void *context LTP_ATTRIBUTE_UNUSED)
37 {
38 	counter++;
39 }
40 
main(void)41 int main(void)
42 {
43 	int pid, i;
44 	union sigval value;
45 	struct sigaction act;
46 
47 	act.sa_flags = SA_SIGINFO;
48 	act.sa_sigaction = myhandler;
49 	sigemptyset(&act.sa_mask);
50 	sigaction(SIGTOTEST, &act, 0);
51 
52 	pid = getpid();
53 
54 	sighold(SIGTOTEST);
55 
56 	for (i = 0; i < NUMCALLS; i++) {
57 		value.sival_int = i;	/* i is just an arbitrary value */
58 		if (sigqueue(pid, SIGTOTEST, value) != 0) {
59 			printf
60 			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
61 			return PTS_UNRESOLVED;
62 		}
63 	}
64 
65 	if (0 != counter) {
66 		printf
67 		    ("Test UNRESOLVED: handler called even though %d has not been removed from the signal mask\n",
68 		     SIGTOTEST);
69 		return PTS_UNRESOLVED;
70 	}
71 
72 	sigrelse(SIGTOTEST);
73 
74 	if (NUMCALLS != counter) {
75 		printf
76 		    ("Test FAILED: %d was queued %d time(s) even though sigqueue was called %d time(s) for %d\n",
77 		     SIGTOTEST, counter, NUMCALLS, SIGTOTEST);
78 		return PTS_FAIL;
79 	}
80 	return PTS_PASS;
81 }
82