#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;
__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);
}
* - 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);
/*
* - 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
* 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)
{
#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 */