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