• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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  *
9  * Updated: 20-06-2011 Peter W. Morreale <pmorreale@novell.com>
10  *
11  * This program tests the assertion that if disp is SIG_HOLD, then the
12  * signal's disposition shall remain unchanged
13  *
14  * Steps:
15  * 1. Register SIGCHLD with myhandler
16  * 2. Add SIGCHLD to the process's signal mask using sigset with disp
17  *    equal to SIG_HOLD
18  * 3. raise SIGCHLD
19  * 4. remove SIGCHLD from the signal mask
20  * 5. Verify that the original disposition hasn't been changed, by making
21  *    sure that SIGCHLD is still handled by myhandler.
22  */
23 
24 
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <string.h>
30 #include "posixtest.h"
31 
32 #define ERR_MSG(f, rc) printf("Failed: func: %s rc: %u errno: %s\n", \
33 						f, rc, strerror(errno))
34 
35 static int handler_called;
36 
myhandler(int signo PTS_ATTRIBUTE_UNUSED)37 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED)
38 {
39 	handler_called = 1;
40 }
41 
main(void)42 int main(void)
43 {
44 	sigset_t pendingset;
45 	struct sigaction act;
46 	int rc;
47 
48 	act.sa_handler = myhandler;
49 	act.sa_flags = 0;
50 	sigemptyset(&act.sa_mask);
51 
52 	rc = sigaction(SIGCHLD, &act, 0);
53 	if (rc) {
54 		ERR_MSG("sigaction()", rc);
55 		return PTS_UNRESOLVED;
56 	}
57 
58 	if (sigset(SIGCHLD, SIG_HOLD) == SIG_ERR) {
59 		perror("Unexpected error while using sigset()");
60 		return PTS_UNRESOLVED;
61 	}
62 
63 	raise(SIGCHLD);
64 
65 	rc = sigpending(&pendingset);
66 	if (rc) {
67 		ERR_MSG("sigpending()", rc);
68 		return PTS_UNRESOLVED;
69 	}
70 
71 	rc = sigismember(&pendingset, SIGCHLD);
72 	if (rc != 1) {
73 		ERR_MSG("sigismember()", rc);
74 		return PTS_UNRESOLVED;
75 	}
76 
77 	sigrelse(SIGCHLD);
78 
79 	if (!handler_called) {
80 		printf("Failed: Signal not delivered\n");
81 		return PTS_FAIL;
82 	}
83 
84 	printf("Test PASSED\n");
85 	return PTS_PASS;
86 }
87