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