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