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 int last_signal = 0;
35 int test_failed = 0;
36 
myhandler(int signo,siginfo_t * info,void * context)37 void myhandler(int signo, siginfo_t * info, void *context)
38 {
39 	printf("%d, ", signo);
40 	if (last_signal >= signo) {
41 		test_failed = 1;
42 	}
43 }
44 
main(void)45 int main(void)
46 {
47 	int pid, rtsig;
48 	union sigval value;
49 	struct sigaction act;
50 	sigset_t mask;
51 
52 	act.sa_flags = SA_SIGINFO;
53 	act.sa_sigaction = myhandler;
54 	sigemptyset(&act.sa_mask);
55 
56 	sigemptyset(&mask);
57 
58 	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
59 		sigaddset(&act.sa_mask, rtsig);
60 		sighold(rtsig);
61 		sigaddset(&mask, rtsig);
62 	}
63 
64 	pid = getpid();
65 	value.sival_int = 5;	/* 5 is just an arbitrary value */
66 
67 	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
68 		sigaction(rtsig, &act, 0);
69 		if (sigqueue(pid, rtsig, value) != 0) {
70 			printf
71 			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
72 			return PTS_UNRESOLVED;
73 		}
74 	}
75 
76 	sigprocmask(SIG_UNBLOCK, &mask, NULL);
77 	printf("\n");
78 
79 	if (test_failed == 1) {
80 		printf
81 		    ("Test FAILED: A pending signal was delivered even though a smaller one is still pending.\n");
82 		return PTS_FAIL;
83 	}
84 
85 	return PTS_PASS;
86 }
87