1 /******************************************************************************
2  * Copyright (c) Crackerjack Project., 2007                                   *
3  * Ported to LTP by Manas Kumar Nayak <maknayak@in.ibm.com>                   *
4  * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>                          *
5  *                                                                            *
6  * This program is free software;  you can redistribute it and/or modify      *
7  * it under the terms of the GNU General Public License as published by       *
8  * the Free Software Foundation; either version 2 of the License, or          *
9  * (at your option) any later version.                                        *
10  *                                                                            *
11  * This program is distributed in the hope that it will be useful,            *
12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of            *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  *
14  * the GNU General Public License for more details.                           *
15  *                                                                            *
16  * You should have received a copy of the GNU General Public License          *
17  * along with this program;  if not, write to the Free Software Foundation,   *
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           *
19  *                                                                            *
20  ******************************************************************************/
21 
22 #include <stdio.h>
23 #include <errno.h>
24 #include <linux/unistd.h>
25 #include <sys/wait.h>
26 
27 #include "test.h"
28 #include "linux_syscall_numbers.h"
29 
30 char *TCID = "exit_group01";
31 int testno;
32 int TST_TOTAL = 1;
33 
verify_exit_group(void)34 static void verify_exit_group(void)
35 {
36 	pid_t cpid, w;
37 	int status;
38 
39 	cpid = fork();
40 	if (cpid == -1)
41 		tst_brkm(TFAIL | TERRNO, NULL, "fork failed");
42 
43 	if (cpid == 0) {
44 		TEST(ltp_syscall(__NR_exit_group, 4));
45 	} else {
46 		w = wait(&status);
47 		if (w == -1)
48 			tst_brkm(TBROK | TERRNO, NULL, "wait() failed");
49 
50 		if (WIFEXITED(status) && (WEXITSTATUS(status) == 4)) {
51 			tst_resm(TPASS, "exit_group() succeeded");
52 		} else {
53 			tst_resm(TFAIL | TERRNO,
54 				 "exit_group() failed (wait status = %d)", w);
55 		}
56 	}
57 }
58 
main(int ac,char ** av)59 int main(int ac, char **av)
60 {
61 	int lc;
62 
63 	tst_parse_opts(ac, av, NULL, NULL);
64 
65 	for (lc = 0; TEST_LOOPING(lc); lc++)
66 		verify_exit_group();
67 
68 	tst_exit();
69 }
70