• 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 the signal shall be ignored
9  if the value of the func parameter is SIG_IGN.
10 
11  How this program tests this assertion is by setting up a handler
12  "myhandler" for SIGCHLD. Then another call to signal() is made about
13  SIGCHLD, this time with SIG_IGN as the value of the func parameter.
14  SIGCHLD should be ignored now, so unless myhandler gets called when
15  SIGCHLD is raised, the test passes, otherwise returns failure.
16 
17 */
18 
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "posixtest.h"
23 
24 int handler_called = 0;
25 
myhandler(int signo)26 void myhandler(int signo)
27 {
28 	printf("SIGCHLD called. Inside handler\n");
29 	handler_called = 1;
30 }
31 
main(void)32 int main(void)
33 {
34 	if (signal(SIGCHLD, myhandler) == SIG_ERR) {
35 		perror("Unexpected error while using signal()");
36 		return PTS_UNRESOLVED;
37 	}
38 
39 	if (signal(SIGCHLD, SIG_IGN) != myhandler) {
40 		perror("Unexpected error while using signal()");
41 		return PTS_UNRESOLVED;
42 	}
43 
44 	raise(SIGCHLD);
45 
46 	if (handler_called == 1) {
47 		printf
48 		    ("Test FAILED: handler was called even though default was expected\n");
49 		return PTS_FAIL;
50 	}
51 	return PTS_PASS;
52 }
53