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 - Call sigwaitinfo() NUMCALLS times, and verify that the queued signals are
18 selected in FIFO order.
19
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 int counter;
34
myhandler(int signo PTS_ATTRIBUTE_UNUSED,siginfo_t * info PTS_ATTRIBUTE_UNUSED,void * context PTS_ATTRIBUTE_UNUSED)35 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED,
36 siginfo_t *info PTS_ATTRIBUTE_UNUSED,
37 void *context PTS_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 sigset_t selectset;
48 siginfo_t info;
49
50 act.sa_flags = SA_SIGINFO;
51 act.sa_sigaction = myhandler;
52 sigemptyset(&act.sa_mask);
53 sigaction(SIGTOTEST, &act, 0);
54
55 pid = getpid();
56
57 sighold(SIGTOTEST);
58
59 for (i = NUMCALLS; i > 0; i--) {
60 value.sival_int = i;
61 if (sigqueue(pid, SIGTOTEST, value) != 0) {
62 printf
63 ("Test FAILED: call to sigqueue did not return success\n");
64 return PTS_FAIL;
65 }
66 }
67
68 sigemptyset(&selectset);
69 sigaddset(&selectset, SIGTOTEST);
70
71 for (i = NUMCALLS; i > 0; i--) {
72 if (sigwaitinfo(&selectset, &info) != SIGTOTEST) {
73 perror
74 ("sigwaitinfo() returned signal other than SIGTOTEST\n");
75 return PTS_UNRESOLVED;
76 }
77 if (info.si_value.sival_int != i) {
78 printf
79 ("Test FAILED: The queued value %d was dequeued before "
80 "the queued value %d even though %d was queued first.\n",
81 info.si_value.sival_int, i, i);
82 return PTS_FAIL;
83 }
84 }
85
86 return PTS_PASS;
87 }
88