• 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  This program tests the assertion that if disp is SIG_HOLD, then the
9  signal shall be added to the process's signal mask.
10 
11  Steps:
12  1. Register SIGCHLD with myhandler
13  2. Add SIGCHLD to the process's signal mask using sigset with disp
14     equal to SIG_HOLD
15  3. raise SIGCHLD
16  4. Verify that SIGCHLD is pending.
17 */
18 
19 
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include "posixtest.h"
26 
27 #define ERR_MSG(f, rc) printf("Failed: func: %s rc: %u errno: %s\n", \
28 						f, rc, strerror(errno))
29 
myhandler(int signo PTS_ATTRIBUTE_UNUSED)30 static void myhandler(int signo PTS_ATTRIBUTE_UNUSED)
31 {
32 	printf("SIGCHLD called. Inside handler\n");
33 }
34 
main(void)35 int main(void)
36 {
37 	sigset_t pendingset;
38 	struct sigaction act;
39 	act.sa_handler = myhandler;
40 	act.sa_flags = 0;
41 	sigemptyset(&act.sa_mask);
42 	int rc;
43 
44 	rc = sigaction(SIGCHLD, &act, 0);
45 	if (rc) {
46 		ERR_MSG("sigaction()", rc);
47 		return PTS_UNRESOLVED;
48 	}
49 
50 	if (sigset(SIGCHLD, SIG_HOLD) == SIG_ERR) {
51 		perror("Unexpected error while using sigset()");
52 		return PTS_UNRESOLVED;
53 	}
54 
55 	raise(SIGCHLD);
56 
57 	rc = sigpending(&pendingset);
58 	if (rc) {
59 		ERR_MSG("sigpending()", rc);
60 		return PTS_UNRESOLVED;
61 	}
62 
63 	if (sigismember(&pendingset, SIGCHLD) != 1) {
64 		printf("Test FAILED: Signal SIGCHLD wasn't hold.\n");
65 		return PTS_FAIL;
66 	}
67 
68 	printf("Test PASSED\n");
69 	return PTS_PASS;
70 }
71