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 for delivery 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
15 sure SA_SIGINFO is set.
16 - Also, make sure that all of these signals are added to the handler's
17 signal mask.
18 - Initially block all of these signals from the process.
19 - Raise all of these signals using sigqueue.
20 - Unblock all of these queued signals simultaneously using sigprocmask.
21 - Verify that the signals are delivered in order from smallest to
22 biggest.
23 */
24
25 #define _XOPEN_REALTIME 1
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
34 static int last_signal;
35 static volatile int test_failed;
36
myhandler(int signo,siginfo_t * info LTP_ATTRIBUTE_UNUSED,void * context LTP_ATTRIBUTE_UNUSED)37 void myhandler(int signo, siginfo_t *info LTP_ATTRIBUTE_UNUSED,
38 void *context LTP_ATTRIBUTE_UNUSED)
39 {
40 printf("%d, ", signo);
41 if (last_signal >= signo) {
42 test_failed = 1;
43 }
44 }
45
main(void)46 int main(void)
47 {
48 int pid, rtsig;
49 union sigval value;
50 struct sigaction act;
51 sigset_t mask;
52
53 act.sa_flags = SA_SIGINFO;
54 act.sa_sigaction = myhandler;
55 sigemptyset(&act.sa_mask);
56
57 sigemptyset(&mask);
58
59 for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
60 sigaddset(&act.sa_mask, rtsig);
61 sighold(rtsig);
62 sigaddset(&mask, rtsig);
63 }
64
65 pid = getpid();
66 value.sival_int = 5; /* 5 is just an arbitrary value */
67
68 for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
69 sigaction(rtsig, &act, 0);
70 if (sigqueue(pid, rtsig, value) != 0) {
71 printf
72 ("Test UNRESOLVED: call to sigqueue did not return success\n");
73 return PTS_UNRESOLVED;
74 }
75 }
76
77 sigprocmask(SIG_UNBLOCK, &mask, NULL);
78 printf("\n");
79
80 if (test_failed == 1) {
81 printf
82 ("Test FAILED: A pending signal was delivered even though a smaller one is still pending.\n");
83 return PTS_FAIL;
84 }
85
86 return PTS_PASS;
87 }
88