]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/pidfd-utils.h
Merge branch 'ci/cache-openwrt-sdk' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / include / pidfd-utils.h
1 /*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 */
5 #ifndef UTIL_LINUX_PIDFD_UTILS
6 #define UTIL_LINUX_PIDFD_UTILS
7
8 #ifdef HAVE_SYS_SYSCALL_H
9 # include <sys/syscall.h>
10
11 /*
12 * If the kernel headers are too old to provide the syscall numbers, let's
13 * define them ourselves. This can be helpful while cross-compiling.
14 */
15 #ifndef __NR_pidfd_send_signal
16 #define __NR_pidfd_send_signal 424
17 #define SYS_pidfd_send_signal __NR_pidfd_send_signal
18 #endif
19 #ifndef __NR_pidfd_open
20 #define __NR_pidfd_open 434
21 #define SYS_pidfd_open __NR_pidfd_open
22 #endif
23
24 # if defined(SYS_pidfd_send_signal) && defined(SYS_pidfd_open)
25 # ifdef HAVE_SYS_PIDFD_H
26 # include <sys/pidfd.h>
27 # endif
28 # include <sys/types.h>
29 # ifndef HAVE_PIDFD_SEND_SIGNAL
30 # include <sys/wait.h>
31 static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
32 unsigned int flags)
33 {
34 return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
35 }
36 # endif
37
38 # ifndef HAVE_PIDFD_OPEN
39 static inline int pidfd_open(pid_t pid, unsigned int flags)
40 {
41 return syscall(SYS_pidfd_open, pid, flags);
42 }
43 # endif
44
45 # define UL_HAVE_PIDFD 1
46
47 # endif /* SYS_pidfd_send_signal */
48 #endif /* HAVE_SYS_SYSCALL_H */
49 #endif /* UTIL_LINUX_PIDFD_UTILS */