1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) Crackerjack Project., 2007 4 * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com> 5 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> 6 */ 7 8/*\ 9 * [Description] 10 * 11 * Tests if waitid() filters children correctly by the group ID. 12 * 13 * - waitid() with GID + 1 returns ECHILD 14 * - waitid() with GID returns correct data 15 */ 16 17#include <stdlib.h> 18#include <sys/wait.h> 19#include "tst_test.h" 20 21static siginfo_t *infop; 22 23static void run(void) 24{ 25 pid_t pid_group; 26 pid_t pid_child; 27 28 pid_child = SAFE_FORK(); 29 if (!pid_child) 30 exit(0); 31 32 pid_group = getpgid(0); 33 34 TST_EXP_FAIL(waitid(P_PGID, pid_group+1, infop, WEXITED), ECHILD); 35 36 memset(infop, 0, sizeof(*infop)); 37 TST_EXP_PASS(waitid(P_PGID, pid_group, infop, WEXITED)); 38 39 TST_EXP_EQ_LI(infop->si_pid, pid_child); 40 TST_EXP_EQ_LI(infop->si_status, 0); 41 TST_EXP_EQ_LI(infop->si_signo, SIGCHLD); 42 TST_EXP_EQ_LI(infop->si_code, CLD_EXITED); 43} 44 45static struct tst_test test = { 46 .test_all = run, 47 .forks_child = 1, 48 .bufs = (struct tst_buffers[]) { 49 {&infop, .size = sizeof(*infop)}, 50 {} 51 } 52}; 53