1 /*
2  * Copyright (c) 2002-3, 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  *  Test that the killpg() function shall send signal sig to the process
9     group specified by prgp.
10     Steps:
11  *  1. Set up a signal handler for the signal that says we have caught the
12  *     signal.
13  *  2. Call killpg on the current process group id, raising the signal.
14  *  3. If signal handler was called, test passed.
15 
16  */
17 
18 #define _XOPEN_SOURCE 600
19 #define SIGTOTEST SIGCHLD
20 
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include "posixtest.h"
26 
handler(int signo)27 void handler(int signo)
28 {
29 	(void) signo;
30 
31 	printf("Caught signal being tested!\n");
32 	printf("Test PASSED\n");
33 	_exit(PTS_PASS);
34 }
35 
main(void)36 int main(void)
37 {
38 	int pgrp;
39 	struct sigaction act;
40 
41 	act.sa_handler = handler;
42 	act.sa_flags = 0;
43 	if (sigemptyset(&act.sa_mask) == -1) {
44 		perror("Error calling sigemptyset\n");
45 		return PTS_UNRESOLVED;
46 	}
47 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
48 		perror("Error calling sigaction\n");
49 		return PTS_UNRESOLVED;
50 	}
51 
52 	if ((pgrp = getpgrp()) == -1) {
53 		printf("Could not get process group number\n");
54 		return PTS_UNRESOLVED;
55 	}
56 
57 	if (killpg(pgrp, SIGTOTEST) != 0) {
58 		printf("Could not raise signal being tested\n");
59 		return PTS_UNRESOLVED;
60 	}
61 
62 	printf("Should have exited from signal handler\n");
63 	printf("Test FAILED\n");
64 	return PTS_FAIL;
65 }
66