1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
5*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
6*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
7*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
10*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
13*49cdfc7eSAndroid Build Coastguard Worker *
14*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
15*49cdfc7eSAndroid Build Coastguard Worker * along with this program.
16*49cdfc7eSAndroid Build Coastguard Worker *
17*49cdfc7eSAndroid Build Coastguard Worker * History
18*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 John George
19*49cdfc7eSAndroid Build Coastguard Worker * -Ported
20*49cdfc7eSAndroid Build Coastguard Worker * 04/2002 wjhuie sigset cleanups
21*49cdfc7eSAndroid Build Coastguard Worker */
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker * DESCRIPTION
25*49cdfc7eSAndroid Build Coastguard Worker * Tests to see if pids returned from fork and waitpid are same
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * ALGORITHM
28*49cdfc7eSAndroid Build Coastguard Worker * Check proper functioning of waitpid with pid = 0 and < -1 with arg
29*49cdfc7eSAndroid Build Coastguard Worker * WUNTRACED
30*49cdfc7eSAndroid Build Coastguard Worker */
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker #include "waitpid_common.h"
33*49cdfc7eSAndroid Build Coastguard Worker
do_child_1(void)34*49cdfc7eSAndroid Build Coastguard Worker static void do_child_1(void)
35*49cdfc7eSAndroid Build Coastguard Worker {
36*49cdfc7eSAndroid Build Coastguard Worker pid_t pid, group;
37*49cdfc7eSAndroid Build Coastguard Worker int i;
38*49cdfc7eSAndroid Build Coastguard Worker int status;
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker group = SAFE_GETPGID(0);
41*49cdfc7eSAndroid Build Coastguard Worker
42*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < MAXKIDS; i++) {
43*49cdfc7eSAndroid Build Coastguard Worker if (i == (MAXKIDS / 2))
44*49cdfc7eSAndroid Build Coastguard Worker SAFE_SETPGID(0, 0);
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK();
47*49cdfc7eSAndroid Build Coastguard Worker if (pid == 0)
48*49cdfc7eSAndroid Build Coastguard Worker do_exit(1);
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker fork_kid_pid[i] = pid;
51*49cdfc7eSAndroid Build Coastguard Worker }
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(waitpid_ret_test(0, &status, WNOHANG | WUNTRACED, 0, 0)))
54*49cdfc7eSAndroid Build Coastguard Worker return;
55*49cdfc7eSAndroid Build Coastguard Worker
56*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(waitpid_ret_test(-group, &status, WNOHANG | WUNTRACED,
57*49cdfc7eSAndroid Build Coastguard Worker 0, 0)))
58*49cdfc7eSAndroid Build Coastguard Worker return;
59*49cdfc7eSAndroid Build Coastguard Worker
60*49cdfc7eSAndroid Build Coastguard Worker TST_CHECKPOINT_WAKE2(0, MAXKIDS);
61*49cdfc7eSAndroid Build Coastguard Worker
62*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(reap_children(0, WUNTRACED, fork_kid_pid + (MAXKIDS / 2),
63*49cdfc7eSAndroid Build Coastguard Worker MAXKIDS / 2)))
64*49cdfc7eSAndroid Build Coastguard Worker return;
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(reap_children(-group, WUNTRACED, fork_kid_pid,
67*49cdfc7eSAndroid Build Coastguard Worker MAXKIDS / 2)))
68*49cdfc7eSAndroid Build Coastguard Worker return;
69*49cdfc7eSAndroid Build Coastguard Worker
70*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "Test PASSED");
71*49cdfc7eSAndroid Build Coastguard Worker }
72*49cdfc7eSAndroid Build Coastguard Worker
73*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
74*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
75*49cdfc7eSAndroid Build Coastguard Worker .needs_checkpoints = 1,
76*49cdfc7eSAndroid Build Coastguard Worker .setup = waitpid_setup,
77*49cdfc7eSAndroid Build Coastguard Worker .cleanup = waitpid_cleanup,
78*49cdfc7eSAndroid Build Coastguard Worker .test_all = waitpid_test,
79*49cdfc7eSAndroid Build Coastguard Worker };
80