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 disp 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 sigset() 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#define _XOPEN_SOURCE 600
21
22#include <signal.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include "posixtest.h"
26
27int handler_called = 0;
28
29void myhandler(int signo)
30{
31	printf("SIGCHLD called. Inside handler\n");
32	handler_called = 1;
33}
34
35int main(void)
36{
37
38	struct sigaction act;
39	act.sa_handler = myhandler;
40	act.sa_flags = 0;
41	sigemptyset(&act.sa_mask);
42
43	if (sigaction(SIGCHLD, &act, 0) != 0) {
44		perror("Unexpected error while using sigaction()");
45		return PTS_UNRESOLVED;
46	}
47
48	if (sigset(SIGCHLD, SIG_DFL) != myhandler) {
49		perror("Unexpected error while using signal()");
50		return PTS_UNRESOLVED;
51	}
52
53	raise(SIGCHLD);
54
55	if (handler_called == 1) {
56		printf
57		    ("Test FAILED: handler was called even though default was expected\n");
58		return PTS_FAIL;
59	}
60	return PTS_PASS;
61}
62