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 the lowest pending signal will be
9 selected by sigwaitinfo() if there are any multiple pending signals in the
10 range SIGRTMIN to SIGRTMAX.
11
12 Steps:
13 - Register for myhandler to be called when any signal between SIGRTMIN
14 and SIGRTMAX is generated, and make sure SA_SIGINFO is set.
15 - Also, make sure that all of these signals are added to the set that
16 will be passed to sigwaitinfo().
17 - Block all of these signals from the process.
18 - Raise all of these signals using sigqueue.
19 - call sigwaitinfo() and verify that it returns SIGRTMIN
20 */
21
22 #define _XOPEN_REALTIME 1
23
24 #include <signal.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include "posixtest.h"
30
myhandler(int signo PTS_ATTRIBUTE_UNUSED,siginfo_t * info PTS_ATTRIBUTE_UNUSED,void * context PTS_ATTRIBUTE_UNUSED)31 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED,
32 siginfo_t *info PTS_ATTRIBUTE_UNUSED,
33 void *context PTS_ATTRIBUTE_UNUSED)
34 {
35 printf("Inside dummy handler\n");
36 }
37
main(void)38 int main(void)
39 {
40 int pid, rtsig;
41 union sigval value;
42 struct sigaction act;
43 sigset_t selectset;
44
45 act.sa_flags = SA_SIGINFO;
46 act.sa_sigaction = myhandler;
47 sigemptyset(&act.sa_mask);
48 sigemptyset(&selectset);
49
50 for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
51 sigaddset(&act.sa_mask, rtsig);
52 sighold(rtsig);
53 sigaddset(&selectset, rtsig);
54 }
55
56 pid = getpid();
57 value.sival_int = 5; /* 5 is just an arbitrary value */
58
59 for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
60 sigaction(rtsig, &act, 0);
61 if (sigqueue(pid, rtsig, value) != 0) {
62 printf
63 ("Test UNRESOLVED: call to sigqueue did not return success\n");
64 return PTS_UNRESOLVED;
65 }
66 }
67
68 if (sigwaitinfo(&selectset, NULL) != SIGRTMIN) {
69 printf
70 ("Test FAILED: sigwaitinfo() did not return the lowest of the multiple pending signals between SIGRTMIN and SIGRTMAX\n");
71 return PTS_FAIL;
72 }
73
74 return PTS_PASS;
75 }
76