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