• 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 #define _XOPEN_SOURCE 600
25 
26 #include <signal.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <string.h>
31 #include "posixtest.h"
32 
33 #define ERR_MSG(f, rc) printf("Failed: func: %s rc: %u errno: %s\n", \
34 						f, rc, strerror(errno))
35 
36 static int handler_called;
37 
myhandler(int signo)38 static void myhandler(int signo)
39 {
40 	handler_called = 1;
41 }
42 
main(void)43 int main(void)
44 {
45 	sigset_t pendingset;
46 	struct sigaction act;
47 	int rc;
48 
49 	act.sa_handler = myhandler;
50 	act.sa_flags = 0;
51 	sigemptyset(&act.sa_mask);
52 
53 	rc = sigaction(SIGCHLD, &act, 0);
54 	if (rc) {
55 		ERR_MSG("sigaction()", rc);
56 		return PTS_UNRESOLVED;
57 	}
58 
59 	if (sigset(SIGCHLD, SIG_HOLD) == SIG_ERR) {
60 		perror("Unexpected error while using sigset()");
61 		return PTS_UNRESOLVED;
62 	}
63 
64 	raise(SIGCHLD);
65 
66 	rc = sigpending(&pendingset);
67 	if (rc) {
68 		ERR_MSG("sigpending()", rc);
69 		return PTS_UNRESOLVED;
70 	}
71 
72 	rc = sigismember(&pendingset, SIGCHLD);
73 	if (rc != 1) {
74 		ERR_MSG("sigismember()", rc);
75 		return PTS_UNRESOLVED;
76 	}
77 
78 	sigrelse(SIGCHLD);
79 
80 	if (!handler_called) {
81 		printf("Failed: Signal not delivered\n");
82 		return PTS_FAIL;
83 	}
84 
85 	printf("Test PASSED\n");
86 	return PTS_PASS;
87 }
88