aboutsummaryrefslogtreecommitdiff
path: root/tests/signal_receive.c
blob: 01c52e8c69965d7ba56ecf6f52e39c88ab2abb40 (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
#include "tests.h"
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void sig_print(const char *signame, const int pid, const int uid)
{
	printf("kill(%d, %s) = 0\n"
	       "--- %s {si_signo=%s, si_code=SI_USER, si_pid=%d"
	       ", si_uid=%d} ---\n",
	       pid, signame, signame, signame, pid, uid);
}

static void
handler(int sig)
{
}

int
main(void)
{
	int sig, pid = getpid(), uid = getuid();
	const struct sigaction act = { .sa_handler = handler };
	sigset_t mask;
	sigemptyset(&mask);

	for (sig = 1; sig <= 31; sig++) {
		if (sig != SIGKILL && sig != SIGSTOP) {
			sigaction(sig, &act, NULL);
			sigaddset(&mask, sig);
		}
	}
	sigprocmask(SIG_UNBLOCK, &mask, NULL);

	for (sig = 1; sig <= 31; sig++) {
		if (sig != SIGKILL && sig != SIGSTOP) {
			if (kill(pid, sig) != 0)
				perror_msg_and_fail("kill: %d", sig);
			sig_print(signal2name(sig), pid, uid);
		}
	}

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