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_SOURCE 600
24 #define _XOPEN_REALTIME 1
25 #define SIGTOTEST SIGRTMIN
26 #define NUMCALLS 5
27
28 #include <signal.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include "posixtest.h"
34
myhandler(int signo,siginfo_t * info,void * context)35 void myhandler(int signo, siginfo_t * info, void *context)
36 {
37 printf("Just a dummy handler\n");
38 }
39
main(void)40 int main(void)
41 {
42 int pid, i;
43 union sigval value;
44 struct sigaction act;
45 sigset_t selectset, pendingset;
46 siginfo_t info;
47
48 act.sa_flags = SA_SIGINFO;
49 act.sa_sigaction = myhandler;
50 sigemptyset(&act.sa_mask);
51 sigaction(SIGTOTEST, &act, 0);
52
53 pid = getpid();
54
55 sighold(SIGTOTEST);
56
57 for (i = NUMCALLS; i > 0; i--) {
58 value.sival_int = 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 sigemptyset(&selectset);
67 sigaddset(&selectset, SIGTOTEST);
68
69 for (i = NUMCALLS; i > 0; i--) {
70 if (sigwaitinfo(&selectset, &info) != SIGTOTEST) {
71 perror
72 ("sigwaitinfo() returned signal other than SIGTOTEST\n");
73 return PTS_UNRESOLVED;
74 }
75 }
76
77 sigemptyset(&pendingset);
78 sigpending(&pendingset);
79 if (sigismember(&pendingset, SIGTOTEST) != 0) {
80 printf
81 ("Test FAILED: Signal %d still pending even after call to sigwaitinfo()\n",
82 SIGTOTEST);
83 return PTS_FAIL;
84 }
85
86 return PTS_PASS;
87 }
88