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