summaryrefslogtreecommitdiff
path: root/tests/qual_signal.c
blob: 3a9d47a77c811d5d9c8db474403d387f4a998f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Check how strace -e signal=set works.
 *
 * Copyright (c) 2016-2021 Dmitry V. Levin <ldv@strace.io>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static pid_t pid;
static uid_t uid;

static void
handler(int sig)
{
}

static void
test_sig(int signo, const char *name)
{
	const struct sigaction act = { .sa_handler = handler };

	if (sigaction(signo, &act, NULL))
		perror_msg_and_fail("sigaction: %d", signo);

	sigset_t mask;
	sigemptyset(&mask);
	sigaddset(&mask, signo);
	if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
		perror_msg_and_fail("sigprocmask: %d", signo);

	if (kill(pid, signo))
		perror_msg_and_fail("kill(%d, %d)", pid, signo);

	if (name && *name)
		printf("--- %s {si_signo=%s, si_code=SI_USER"
		       ", si_pid=%d, si_uid=%d} ---\n",
		       name, name, pid, uid);
}

int
main(int ac, const char **av)
{
	assert(ac & 1);

	pid = getpid();
	uid = geteuid();

	for (int i = 1; i < ac; i += 2)
		test_sig(atoi(av[i]), av[i + 1]);

	puts("+++ exited with 0 +++");
	return 0;
}