• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *  Test that the sigwaitinfo() function shall select the pending signal
9     from the set set, and atomically clear it from the system's set of
10     pending signals.
11 
12     Steps:
13     1. Register signal SIGTOTEST with the handler myhandler
14     2. Block SIGTOTEST from the process
15     3. Raise the signal, causing it to be pending
16     4. Call sigwaitinfo() and verify that the signal is no longer pending.
17  */
18 
19 #define _XOPEN_REALTIME 1
20 #define SIGTOTEST SIGUSR1
21 
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <sys/wait.h>
27 #include "posixtest.h"
28 
myhandler(int signo PTS_ATTRIBUTE_UNUSED)29 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED)
30 {
31 	printf("Inside handler\n");
32 }
33 
main(void)34 int main(void)
35 {
36 
37 	struct sigaction act;
38 	sigset_t pendingset, selectset;
39 
40 	act.sa_flags = 0;
41 	act.sa_handler = myhandler;
42 
43 	sigemptyset(&pendingset);
44 	sigemptyset(&selectset);
45 	sigaddset(&selectset, SIGTOTEST);
46 	sigemptyset(&act.sa_mask);
47 
48 	sigaction(SIGTOTEST, &act, 0);
49 	sighold(SIGTOTEST);
50 	raise(SIGTOTEST);
51 
52 	sigpending(&pendingset);
53 
54 	if (sigismember(&pendingset, SIGTOTEST) != 1) {
55 		perror("SIGTOTEST is not pending\n");
56 		return PTS_UNRESOLVED;
57 	}
58 
59 	if (sigwaitinfo(&selectset, NULL) == -1) {
60 		perror("Call to sigwaitinfo() failed\n");
61 		return PTS_UNRESOLVED;
62 	}
63 
64 	sigemptyset(&pendingset);
65 	sigpending(&pendingset);
66 
67 	if (sigismember(&pendingset, SIGTOTEST) != 0) {
68 		printf
69 		    ("Test FAILED: Signal %d still pending even after call to sigwaitinfo()\n",
70 		     SIGTOTEST);
71 		return PTS_FAIL;
72 	}
73 
74 	printf("Test PASSED\n");
75 	return PTS_PASS;
76 }
77