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 SIGTOTEST SIGCHLD
19 
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "posixtest.h"
25 
handler(int signo)26 void handler(int signo)
27 {
28 	(void) signo;
29 
30 	printf("Caught signal being tested!\n");
31 	printf("Test PASSED\n");
32 	_exit(PTS_PASS);
33 }
34 
main(void)35 int main(void)
36 {
37 	int pgrp;
38 	struct sigaction act;
39 
40 	act.sa_handler = handler;
41 	act.sa_flags = 0;
42 	if (sigemptyset(&act.sa_mask) == -1) {
43 		perror("Error calling sigemptyset\n");
44 		return PTS_UNRESOLVED;
45 	}
46 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
47 		perror("Error calling sigaction\n");
48 		return PTS_UNRESOLVED;
49 	}
50 
51 	if ((pgrp = getpgrp()) == -1) {
52 		printf("Could not get process group number\n");
53 		return PTS_UNRESOLVED;
54 	}
55 
56 	if (killpg(pgrp, SIGTOTEST) != 0) {
57 		printf("Could not raise signal being tested\n");
58 		return PTS_UNRESOLVED;
59 	}
60 
61 	printf("Should have exited from signal handler\n");
62 	printf("Test FAILED\n");
63 	return PTS_FAIL;
64 }
65