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 verifies that if the value of pid causes signo to be
9 generated for the sending process, and if signo is not blocked for
10 the calling thread and if no other thread has signo unblocked or is
11 waiting in a sigwait() function for signo, then signal SIGTOTEST
12 is delivered to the calling thread before the sigqueue() function returns.
13
14 Steps:
15 - Register for myhandler to be called when SIGTOTEST is called, and make
16 sure SA_SIGINFO is set.
17 - Using sigqueue(), send SIGTOTEST to the current process.
18 - Inside handler, verify that the global return_val variable has not been
19 set yet to the return value of sigqueue. If it has, then that means that
20 sigqueu has returned before the handler finished executing, and thus is
21 a FAILED test.
22 - Also before the program ends, verify that the handler
23 has been called.
24 */
25
26 #define _XOPEN_REALTIME 1
27 #define SIGTOTEST SIGRTMIN
28 #define NUMCALLS 5
29
30 #include <signal.h>
31 #include <stdio.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <errno.h>
35 #include "posixtest.h"
36
37 static int return_val = 1;
38 static volatile int handler_called;
39
myhandler(int signo PTS_ATTRIBUTE_UNUSED,siginfo_t * info PTS_ATTRIBUTE_UNUSED,void * context PTS_ATTRIBUTE_UNUSED)40 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED,
41 siginfo_t *info PTS_ATTRIBUTE_UNUSED,
42 void *context PTS_ATTRIBUTE_UNUSED)
43 {
44 handler_called = 1;
45 if (return_val != 1) {
46 printf
47 ("Test FAILED: sigqueue() seems to have returned before handler finished executing.\n");
48 exit(1);
49 }
50 }
51
main(void)52 int main(void)
53 {
54 int pid;
55 union sigval value;
56 struct sigaction act;
57
58 act.sa_flags = SA_SIGINFO;
59 act.sa_sigaction = myhandler;
60 sigemptyset(&act.sa_mask);
61 sigaction(SIGTOTEST, &act, 0);
62
63 value.sival_int = 0; /* 0 is just an arbitrary value */
64 pid = getpid();
65
66 if ((return_val = sigqueue(pid, SIGTOTEST, value)) != 0) {
67 printf
68 ("Test UNRESOLVED: call to sigqueue did not return success\n");
69 return PTS_UNRESOLVED;
70 }
71
72 if (handler_called != 1) {
73 printf("Test FAILED: signal was not delivered to process\n");
74 return PTS_FAIL;
75 }
76 return PTS_PASS;
77 }
78