• 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  This program tests the assertion that if SA_SIGINFO is not set, then the
9  signal shall be received at least once
10 
11  Steps:
12  - Register for myhandler to be called when SIGTOTEST is called, and make
13    sure SA_SIGINFO is NOT SET.
14  - Block signal SIGTOTEST from the process.
15  - Using sigqueue(), send NUMCALLS instances of SIGTOTEST to the current
16    process.
17  - Verify that the handler is executed at least once AFTER SIGTOTEST
18    is unblocked.
19  */
20 
21 #define _XOPEN_REALTIME 1
22 #define SIGTOTEST SIGRTMIN
23 #define NUMCALLS 5
24 
25 #include <signal.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include "posixtest.h"
31 
32 static volatile int counter = 0;
33 
myhandler(int signo PTS_ATTRIBUTE_UNUSED)34 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED)
35 {
36 	counter++;
37 }
38 
main(void)39 int main(void)
40 {
41 	int pid, i;
42 	union sigval value;
43 	struct sigaction act;
44 
45 	act.sa_handler = myhandler;
46 	act.sa_flags = 0;
47 	sigemptyset(&act.sa_mask);
48 	sigaction(SIGTOTEST, &act, 0);
49 
50 	value.sival_int = 0;	/* 0 is just an arbitrary value */
51 	pid = getpid();
52 
53 	sighold(SIGTOTEST);
54 
55 	for (i = 0; i < NUMCALLS; i++) {
56 		if (sigqueue(pid, SIGTOTEST, value) != 0) {
57 			printf
58 			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
59 			return PTS_UNRESOLVED;
60 		}
61 	}
62 
63 	if (0 != counter) {
64 		printf
65 		    ("Test UNRESOLVED: handler called even though %d has not been removed from the signal mask\n",
66 		     SIGTOTEST);
67 		return PTS_UNRESOLVED;
68 	}
69 
70 	sigrelse(SIGTOTEST);
71 
72 	if (counter < 1) {
73 		printf("Test FAILED: %d was not received even once\n",
74 		       SIGTOTEST);
75 		return PTS_FAIL;
76 	}
77 	printf("Test PASSED: %d was received %d times.\n", SIGTOTEST, counter);
78 	return PTS_PASS;
79 }
80