1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker */
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * Basic test for PR_SET_PDEATHSIG/PR_GET_PDEATHSIG
10*49cdfc7eSAndroid Build Coastguard Worker *
11*49cdfc7eSAndroid Build Coastguard Worker * Use PR_SET_PDEATHSIG to set SIGUSR2 signal and PR_GET_PDEATHSIG should
12*49cdfc7eSAndroid Build Coastguard Worker * receive this signal.
13*49cdfc7eSAndroid Build Coastguard Worker */
14*49cdfc7eSAndroid Build Coastguard Worker
15*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <sys/prctl.h>
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
20*49cdfc7eSAndroid Build Coastguard Worker
verify_prctl(void)21*49cdfc7eSAndroid Build Coastguard Worker static void verify_prctl(void)
22*49cdfc7eSAndroid Build Coastguard Worker {
23*49cdfc7eSAndroid Build Coastguard Worker int get_sig = 0;
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker TEST(prctl(PR_SET_PDEATHSIG, SIGUSR2));
26*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1) {
27*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "prctl(PR_SET_PDEATHSIG) failed");
28*49cdfc7eSAndroid Build Coastguard Worker return;
29*49cdfc7eSAndroid Build Coastguard Worker }
30*49cdfc7eSAndroid Build Coastguard Worker
31*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "prctl(PR_SET_PDEATHSIG) succeeded");
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Worker TEST(prctl(PR_GET_PDEATHSIG, &get_sig));
34*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1) {
35*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "prctl(PR_GET_PDEATHSIG) failed");
36*49cdfc7eSAndroid Build Coastguard Worker return;
37*49cdfc7eSAndroid Build Coastguard Worker }
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker if (get_sig == SIGUSR2) {
40*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS,
41*49cdfc7eSAndroid Build Coastguard Worker "prctl(PR_GET_PDEATHSIG) got expected death signal");
42*49cdfc7eSAndroid Build Coastguard Worker } else {
43*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "prctl(PR_GET_PDEATHSIG) got death signal %d, expected %d",
44*49cdfc7eSAndroid Build Coastguard Worker get_sig, SIGUSR2);
45*49cdfc7eSAndroid Build Coastguard Worker }
46*49cdfc7eSAndroid Build Coastguard Worker }
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
49*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_prctl,
50*49cdfc7eSAndroid Build Coastguard Worker };
51