1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4 * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
5 * AUTHOR	: Dave Baumgartner
6 * CO-PILOT	: Barrie Kletscher
7 */
8
9/*\
10 * [Description]
11 *
12 * Test SIGKILL for these items:
13 *	1. SIGKILL can not be set to be ignored, errno:EINVAL (POSIX).
14 *	2. SIGKILL can not be reset to default, errno:EINVAL (POSIX).
15 *	3. SIGKILL can not be set to be caught, errno:EINVAL (POSIX).
16 *	4. SIGKILL can not be ignored.
17 *	5. SIGKILL is reset to default failed but processed by default.
18 *	6. SIGKILL can not be caught.
19 */
20
21#include <stdlib.h>
22#include "tst_test.h"
23
24static void catchsig(int sig)
25{
26	(void)sig;
27}
28
29static struct tcase {
30	void (*sighandler)(int i);
31	int kill;
32} tcases[] = {
33	{SIG_IGN, 0},
34	{SIG_DFL, 0},
35	{catchsig, 0},
36	{SIG_IGN, 1},
37	{SIG_DFL, 1},
38	{catchsig, 1},
39};
40
41static void do_test(unsigned int n)
42{
43	pid_t pid;
44	int res;
45
46	struct tcase *tc = &tcases[n];
47
48	pid = SAFE_FORK();
49
50	if (!pid) {
51		if (tc->kill) {
52			signal(SIGKILL, tc->sighandler);
53			pause();
54		}
55
56		TST_EXP_FAIL2((long)signal(SIGKILL, tc->sighandler), EINVAL);
57		return;
58	}
59
60	if (!tc->kill) {
61		SAFE_WAITPID(pid, &res, 0);
62		return;
63	}
64
65	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
66	SAFE_KILL(pid, SIGKILL);
67	SAFE_WAITPID(pid, &res, 0);
68
69	if (WIFSIGNALED(res))
70		TST_EXP_EQ_SSZ(WTERMSIG(res), SIGKILL);
71	else
72		tst_res(TFAIL, "Child not killed by signal");
73}
74
75static struct tst_test test = {
76	.tcnt = ARRAY_SIZE(tcases),
77	.forks_child = 1,
78	.test = do_test,
79};
80