10dc076565f772bb1953209fb69ea150b494aaa40robbiew/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2003, Intel Corporation. All rights reserved.
30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license.  For the full content
52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this
60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree.
70dc076565f772bb1953209fb69ea150b494aaa40robbiew
82c28215423293e443469a07ae7011135d058b671Garrett Cooper This program tests the assertion that the default handling of the
90dc076565f772bb1953209fb69ea150b494aaa40robbiew signal shall occur if the value of the func parameter is SIG_DFL.
100dc076565f772bb1953209fb69ea150b494aaa40robbiew
112c28215423293e443469a07ae7011135d058b671Garrett Cooper How this program tests this assertion by setting up a handler
120dc076565f772bb1953209fb69ea150b494aaa40robbiew "myhandler" for SIGCHLD. Then another call to signal() is made about
130dc076565f772bb1953209fb69ea150b494aaa40robbiew SIGCHLD, this time with SIG_DFL as the value of the func parameter.
140dc076565f772bb1953209fb69ea150b494aaa40robbiew The default action for SIGCHLD is to be ignored, so unless myhandler
150dc076565f772bb1953209fb69ea150b494aaa40robbiew gets called when SIGCHLD is raised, the test passess, otherwise
160dc076565f772bb1953209fb69ea150b494aaa40robbiew returns failure.
172c28215423293e443469a07ae7011135d058b671Garrett Cooper
180dc076565f772bb1953209fb69ea150b494aaa40robbiew*/
190dc076565f772bb1953209fb69ea150b494aaa40robbiew
200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <signal.h>
210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
220dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdlib.h>
230dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
240dc076565f772bb1953209fb69ea150b494aaa40robbiew
250dc076565f772bb1953209fb69ea150b494aaa40robbiewint handler_called = 0;
260dc076565f772bb1953209fb69ea150b494aaa40robbiew
270dc076565f772bb1953209fb69ea150b494aaa40robbiewvoid myhandler(int signo)
280dc076565f772bb1953209fb69ea150b494aaa40robbiew{
290dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("SIGCHLD called. Inside handler\n");
300dc076565f772bb1953209fb69ea150b494aaa40robbiew	handler_called = 1;
310dc076565f772bb1953209fb69ea150b494aaa40robbiew}
320dc076565f772bb1953209fb69ea150b494aaa40robbiew
334ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
340dc076565f772bb1953209fb69ea150b494aaa40robbiew{
350dc076565f772bb1953209fb69ea150b494aaa40robbiew	if (signal(SIGCHLD, myhandler) == SIG_ERR) {
36354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		perror("Unexpected error while using signal()");
37354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		return PTS_UNRESOLVED;
38354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	}
390dc076565f772bb1953209fb69ea150b494aaa40robbiew
40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (signal(SIGCHLD, SIG_DFL) != myhandler) {
41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		perror("Unexpected error while using signal()");
42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		return PTS_UNRESOLVED;
43354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	}
440dc076565f772bb1953209fb69ea150b494aaa40robbiew
450dc076565f772bb1953209fb69ea150b494aaa40robbiew	raise(SIGCHLD);
462c28215423293e443469a07ae7011135d058b671Garrett Cooper
470dc076565f772bb1953209fb69ea150b494aaa40robbiew	if (handler_called == 1) {
48354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		printf
49354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		    ("Test FAILED: handler was called even though default was expected\n");
500dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
512c28215423293e443469a07ae7011135d058b671Garrett Cooper	}
520dc076565f772bb1953209fb69ea150b494aaa40robbiew	return PTS_PASS;
53ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
54