]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/process_utils.h
tree-wide: use struct clone_args directly
[mirror_lxc.git] / src / lxc / process_utils.h
index e0157c631b22829c91e8bb5b3fa57c26e196b0b6..d2bf97802d1f66316932edd560442768fe0c9ba4 100644 (file)
@@ -3,20 +3,22 @@
 #ifndef __LXC_PROCESS_UTILS_H
 #define __LXC_PROCESS_UTILS_H
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-#include <linux/sched.h>
+#include "config.h"
+
 #include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#if HAVE_SYS_PIDFD_H
+#include <sys/pidfd.h>
+#endif
+
 #include "compiler.h"
-#include "config.h"
 #include "syscall_numbers.h"
 
 #ifndef CSIGNAL
 #endif
 
 /* waitid */
+#if !HAVE_SYS_PIDFD_H
 #ifndef P_PIDFD
 #define P_PIDFD 3
 #endif
+#endif
 
 #ifndef CLONE_ARGS_SIZE_VER0
 #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
 #define u64_to_ptr(x) ((void *)(uintptr_t)x)
 #endif
 
-struct lxc_clone_args {
+#if !HAVE_STRUCT_CLONE_ARGS
+struct clone_args {
        __aligned_u64 flags;
        __aligned_u64 pidfd;
        __aligned_u64 child_tid;
@@ -173,8 +178,9 @@ struct lxc_clone_args {
        __aligned_u64 set_tid_size;
        __aligned_u64 cgroup;
 };
+#endif
 
-__returns_twice static inline pid_t lxc_clone3(struct lxc_clone_args *args, size_t size)
+__returns_twice static inline pid_t lxc_clone3(struct clone_args *args, size_t size)
 {
        return syscall(__NR_clone3, args, size);
 }
@@ -256,7 +262,7 @@ __hidden extern pid_t lxc_raw_legacy_clone(unsigned long flags, int *pidfd);
 __hidden extern pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args, unsigned long flags,
                                       int *pidfd);
 
-#ifndef HAVE_EXECVEAT
+#if !HAVE_EXECVEAT
 static inline int execveat(int dirfd, const char *pathname, char *const argv[],
                           char *const envp[], int flags)
 {
@@ -288,4 +294,16 @@ static inline pid_t lxc_raw_gettid(void)
 __hidden extern int lxc_raw_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
                                              unsigned int flags);
 
+static inline const char *signal_name(int sig)
+{
+       const char *s;
+
+#if HAVE_SIGDESCR_NP
+       s = sigdescr_np(sig);
+#else
+       s = "UNSUPPORTED";
+#endif
+       return s ?: "INVALID_SIGNAL_NUMBER";
+}
+
 #endif /* __LXC_PROCESS_UTILS_H */