1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) Crackerjack Project., 2007
4f08c3bdfSopenharmony_ci * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
5f08c3bdfSopenharmony_ci */
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ci/*\
8f08c3bdfSopenharmony_ci * [Description]
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci * This test is checking if waitid() syscall recognizes a process that has been
11f08c3bdfSopenharmony_ci * killed with SIGKILL.
12f08c3bdfSopenharmony_ci */
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ci#include <time.h>
15f08c3bdfSopenharmony_ci#include <stdlib.h>
16f08c3bdfSopenharmony_ci#include <sys/wait.h>
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_cistatic siginfo_t *infop;
20f08c3bdfSopenharmony_ci
21f08c3bdfSopenharmony_cistatic void run(void)
22f08c3bdfSopenharmony_ci{
23f08c3bdfSopenharmony_ci	pid_t pidchild;
24f08c3bdfSopenharmony_ci
25f08c3bdfSopenharmony_ci	pidchild = SAFE_FORK();
26f08c3bdfSopenharmony_ci	if (!pidchild) {
27f08c3bdfSopenharmony_ci		pause();
28f08c3bdfSopenharmony_ci		return;
29f08c3bdfSopenharmony_ci	}
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_ci	SAFE_KILL(pidchild, SIGKILL);
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ci	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
34f08c3bdfSopenharmony_ci	TST_EXP_EQ_LI(infop->si_pid, pidchild);
35f08c3bdfSopenharmony_ci	TST_EXP_EQ_LI(infop->si_status, SIGKILL);
36f08c3bdfSopenharmony_ci	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
37f08c3bdfSopenharmony_ci	TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
38f08c3bdfSopenharmony_ci}
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_cistatic struct tst_test test = {
41f08c3bdfSopenharmony_ci	.test_all = run,
42f08c3bdfSopenharmony_ci	.forks_child = 1,
43f08c3bdfSopenharmony_ci	.bufs =	(struct tst_buffers[]) {
44f08c3bdfSopenharmony_ci		{&infop, .size = sizeof(*infop)},
45f08c3bdfSopenharmony_ci		{},
46f08c3bdfSopenharmony_ci	},
47f08c3bdfSopenharmony_ci};
48