• 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 #define _XOPEN_SOURCE 600
20 
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <string.h>
26 #include "posixtest.h"
27 
28 #define ERR_MSG(f, rc) printf("Failed: func: %s rc: %u errno: %s\n", \
29 						f, rc, strerror(errno))
30 
myhandler(int signo)31 void myhandler(int signo)
32 {
33 	printf("SIGCHLD called. Inside handler\n");
34 }
35 
main(void)36 int main(void)
37 {
38 	sigset_t pendingset;
39 	struct sigaction act;
40 	act.sa_handler = myhandler;
41 	act.sa_flags = 0;
42 	sigemptyset(&act.sa_mask);
43 	int rc;
44 
45 	rc = sigaction(SIGCHLD, &act, 0);
46 	if (rc) {
47 		ERR_MSG("sigaction()", rc);
48 		return PTS_UNRESOLVED;
49 	}
50 
51 	if (sigset(SIGCHLD, SIG_HOLD) == SIG_ERR) {
52 		perror("Unexpected error while using sigset()");
53 		return PTS_UNRESOLVED;
54 	}
55 
56 	raise(SIGCHLD);
57 
58 	rc = sigpending(&pendingset);
59 	if (rc) {
60 		ERR_MSG("sigpending()", rc);
61 		return PTS_UNRESOLVED;
62 	}
63 
64 	if (sigismember(&pendingset, SIGCHLD) != 1) {
65 		printf("Test FAILED: Signal SIGCHLD wasn't hold.\n");
66 		return PTS_FAIL;
67 	}
68 
69 	printf("Test PASSED\n");
70 	return PTS_PASS;
71 }
72