• 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 there aren't any more queued signals
9  for the selected signal, then the pending indication of that signal is
10  reset.
11 
12  Steps:
13  - Register for myhandler to be called when SIGTOTEST is called, and make
14    sure SA_SIGINFO is set.
15  - Block signal SIGTOTEST from the process.
16  - Using sigqueue(), send NUMCALLS instances of SIGTOTEST to the current
17    process.
18  - Call sigwaitinfo() NUMCALLS times, and verify that the pending indication
19    for signal SIGTOTEST has been reset.
20 
21  */
22 
23 #define _XOPEN_REALTIME 1
24 #define SIGTOTEST SIGRTMIN
25 #define NUMCALLS 5
26 
27 #include <signal.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #include "posixtest.h"
33 
myhandler(int signo PTS_ATTRIBUTE_UNUSED,siginfo_t * info PTS_ATTRIBUTE_UNUSED,void * context PTS_ATTRIBUTE_UNUSED)34 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED,
35 	siginfo_t *info PTS_ATTRIBUTE_UNUSED,
36 	void *context PTS_ATTRIBUTE_UNUSED)
37 {
38 	printf("Just a dummy handler\n");
39 }
40 
main(void)41 int main(void)
42 {
43 	int pid, i;
44 	union sigval value;
45 	struct sigaction act;
46 	sigset_t selectset, pendingset;
47 	siginfo_t info;
48 
49 	act.sa_flags = SA_SIGINFO;
50 	act.sa_sigaction = myhandler;
51 	sigemptyset(&act.sa_mask);
52 	sigaction(SIGTOTEST, &act, 0);
53 
54 	pid = getpid();
55 
56 	sighold(SIGTOTEST);
57 
58 	for (i = NUMCALLS; i > 0; i--) {
59 		value.sival_int = i;
60 		if (sigqueue(pid, SIGTOTEST, value) != 0) {
61 			printf
62 			    ("Test FAILED: call to sigqueue did not return success\n");
63 			return PTS_FAIL;
64 		}
65 	}
66 
67 	sigemptyset(&selectset);
68 	sigaddset(&selectset, SIGTOTEST);
69 
70 	for (i = NUMCALLS; i > 0; i--) {
71 		if (sigwaitinfo(&selectset, &info) != SIGTOTEST) {
72 			perror
73 			    ("sigwaitinfo() returned signal other than SIGTOTEST\n");
74 			return PTS_UNRESOLVED;
75 		}
76 	}
77 
78 	sigemptyset(&pendingset);
79 	sigpending(&pendingset);
80 	if (sigismember(&pendingset, SIGTOTEST) != 0) {
81 		printf
82 		    ("Test FAILED: Signal %d still pending even after call to sigwaitinfo()\n",
83 		     SIGTOTEST);
84 		return PTS_FAIL;
85 	}
86 
87 	return PTS_PASS;
88 }
89