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 = -1 and 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;
37*49cdfc7eSAndroid Build Coastguard Worker int i;
38*49cdfc7eSAndroid Build Coastguard Worker int status;
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < MAXKIDS; i++) {
41*49cdfc7eSAndroid Build Coastguard Worker if (i == (MAXKIDS / 2))
42*49cdfc7eSAndroid Build Coastguard Worker SAFE_SETPGID(0, 0);
43*49cdfc7eSAndroid Build Coastguard Worker
44*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK();
45*49cdfc7eSAndroid Build Coastguard Worker if (pid == 0)
46*49cdfc7eSAndroid Build Coastguard Worker do_exit(1);
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker fork_kid_pid[i] = pid;
49*49cdfc7eSAndroid Build Coastguard Worker }
50*49cdfc7eSAndroid Build Coastguard Worker
51*49cdfc7eSAndroid Build Coastguard Worker /* Check that waitpid with WNOHANG|WUNTRACED returns
52*49cdfc7eSAndroid Build Coastguard Worker * zero
53*49cdfc7eSAndroid Build Coastguard Worker */
54*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(waitpid_ret_test(-1, &status, WNOHANG | WUNTRACED, 0, 0)))
55*49cdfc7eSAndroid Build Coastguard Worker return;
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Worker TST_CHECKPOINT_WAKE2(0, MAXKIDS);
58*49cdfc7eSAndroid Build Coastguard Worker
59*49cdfc7eSAndroid Build Coastguard Worker if (TST_TRACE(reap_children(-1, WUNTRACED, fork_kid_pid, MAXKIDS)))
60*49cdfc7eSAndroid Build Coastguard Worker return;
61*49cdfc7eSAndroid Build Coastguard Worker
62*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "Test PASSED");
63*49cdfc7eSAndroid Build Coastguard Worker }
64*49cdfc7eSAndroid Build Coastguard Worker
65*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
66*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
67*49cdfc7eSAndroid Build Coastguard Worker .needs_checkpoints = 1,
68*49cdfc7eSAndroid Build Coastguard Worker .setup = waitpid_setup,
69*49cdfc7eSAndroid Build Coastguard Worker .cleanup = waitpid_cleanup,
70*49cdfc7eSAndroid Build Coastguard Worker .test_all = waitpid_test,
71*49cdfc7eSAndroid Build Coastguard Worker };
72