]> 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 61b0e412b7a5be6e27e9e9608020f8b936c35275..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);
 }
@@ -209,7 +215,7 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...
  * - should call lxc_raw_getpid():
  *   The child should use lxc_raw_getpid() to retrieve its pid.
  */
-extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
+__hidden extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
 
 
 /*
@@ -239,8 +245,8 @@ extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
  * - must call lxc_raw_getpid():
  *   The child must use lxc_raw_getpid() to retrieve its pid.
  */
-extern pid_t lxc_raw_clone(unsigned long flags, int *pidfd);
-extern pid_t lxc_raw_legacy_clone(unsigned long flags, int *pidfd);
+__hidden extern pid_t lxc_raw_clone(unsigned long flags, int *pidfd);
+__hidden extern pid_t lxc_raw_legacy_clone(unsigned long flags, int *pidfd);
 
 /*
  * lxc_raw_clone_cb() - create a new process
@@ -253,10 +259,10 @@ extern pid_t lxc_raw_legacy_clone(unsigned long flags, int *pidfd);
  * All other comments that apply to lxc_raw_clone() apply to lxc_raw_clone_cb()
  * as well.
  */
-extern pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args,
-                             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)
 {
@@ -285,7 +291,19 @@ static inline pid_t lxc_raw_gettid(void)
 #endif
 }
 
-extern int lxc_raw_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
-                                    unsigned int flags);
+__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 */