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