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