File: pidfd_send_signal.c

package info (click to toggle)
strace 5.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 49,332 kB
  • sloc: ansic: 113,177; sh: 8,831; makefile: 3,108; awk: 364; perl: 267; sed: 9
file content (77 lines) | stat: -rw-r--r-- 1,824 bytes parent folder | download | duplicates (3)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Check decoding of pidfd_send_signal syscall.
 *
 * Copyright (c) 2015-2020 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include <unistd.h>
#include "scno.h"
#include "pidns.h"

#ifdef __NR_pidfd_send_signal

# include <fcntl.h>
# include <stdio.h>
# include <signal.h>

static const char *errstr;

static long
sys_pidfd_send_signal(int pidfd, int sig, const void *info, int flags)
{
	kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
	kernel_ulong_t arg1 = fill | (unsigned int) pidfd;
	kernel_ulong_t arg2 = fill | (unsigned int) sig;
	kernel_ulong_t arg3 = (unsigned long) info;
	kernel_ulong_t arg4 = fill | (unsigned int) flags;

	long rc = syscall(__NR_pidfd_send_signal, arg1, arg2, arg3, arg4);
	errstr = sprintrc(rc);
	return rc;
}

int
main(void)
{
	PIDNS_TEST_INIT;

	static const char null_path[] = "/dev/null";

	int fd = open(null_path, O_RDONLY);
	if (fd < 0)
		perror_msg_and_fail("open: %s", null_path);

	TAIL_ALLOC_OBJECT_CONST_PTR(siginfo_t, si);
	const void *esi = (const void *) si + 1;

	sys_pidfd_send_signal(fd, SIGUSR1, esi, 0);
	pidns_print_leader();
	printf("pidfd_send_signal(%d, SIGUSR1, %p, 0) = %s\n",
	       fd, esi, errstr);

	si->si_signo = SIGUSR1;
	si->si_code = SI_QUEUE;
	si->si_pid = getpid();

	sys_pidfd_send_signal(fd, SIGUSR2, si, -1);
	pidns_print_leader();
	printf("pidfd_send_signal(%d, SIGUSR2, {si_signo=SIGUSR1"
	       ", si_code=SI_QUEUE, si_errno=%u, si_pid=%d%s, si_uid=%d"
	       ", si_value={int=%d, ptr=%p}}, %#x) = %s\n",
	       fd, si->si_errno, si->si_pid, pidns_pid2str(PT_TGID), si->si_uid,
	       si->si_int, si->si_ptr, -1U, errstr);

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

#else

SKIP_MAIN_UNDEFINED("__NR_pidfd_send_signal")

#endif