summaryrefslogtreecommitdiffstats
path: root/include/pidfd-utils.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
commitcfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch)
treed0baf160cbee3195249d095f85e52d20c21acf02 /include/pidfd-utils.h
parentInitial commit. (diff)
downloadutil-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz
util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/pidfd-utils.h')
-rw-r--r--include/pidfd-utils.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/pidfd-utils.h b/include/pidfd-utils.h
new file mode 100644
index 0000000..ff0bc4c
--- /dev/null
+++ b/include/pidfd-utils.h
@@ -0,0 +1,49 @@
+/*
+ * No copyright is claimed. This code is in the public domain; do with
+ * it what you wish.
+ */
+#ifndef UTIL_LINUX_PIDFD_UTILS
+#define UTIL_LINUX_PIDFD_UTILS
+
+#ifdef HAVE_SYS_SYSCALL_H
+# include <sys/syscall.h>
+
+/*
+ * If the kernel headers are too old to provide the syscall numbers, let's
+ * define them ourselves. This can be helpful while cross-compiling.
+ */
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal 424
+#define SYS_pidfd_send_signal __NR_pidfd_send_signal
+#endif
+#ifndef __NR_pidfd_open
+#define __NR_pidfd_open 434
+#define SYS_pidfd_open __NR_pidfd_open
+#endif
+
+# if defined(SYS_pidfd_send_signal) && defined(SYS_pidfd_open)
+# ifdef HAVE_SYS_PIDFD_H
+# include <sys/pidfd.h>
+# endif
+# include <sys/types.h>
+# ifndef HAVE_PIDFD_SEND_SIGNAL
+# include <sys/wait.h>
+static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
+ unsigned int flags)
+{
+ return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
+}
+# endif
+
+# ifndef HAVE_PIDFD_OPEN
+static inline int pidfd_open(pid_t pid, unsigned int flags)
+{
+ return syscall(SYS_pidfd_open, pid, flags);
+}
+# endif
+
+# define UL_HAVE_PIDFD 1
+
+# endif /* SYS_pidfd_send_signal */
+#endif /* HAVE_SYS_SYSCALL_H */
+#endif /* UTIL_LINUX_PIDFD_UTILS */