syscall_wrappers: move signalfd()

parent dd425984
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "nbd.h" #include "nbd.h"
#include "storage.h" #include "storage.h"
#include "storage_utils.h" #include "storage_utils.h"
#include "syscall_wrappers.h"
#include "utils.h" #include "utils.h"
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define _GNU_SOURCE 1 #define _GNU_SOURCE 1
#endif #endif
#include <asm/unistd.h> #include <asm/unistd.h>
#include <errno.h>
#include <linux/keyctl.h> #include <linux/keyctl.h>
#include <sched.h> #include <sched.h>
#include <stdint.h> #include <stdint.h>
...@@ -37,6 +38,10 @@ ...@@ -37,6 +38,10 @@
#include <linux/memfd.h> #include <linux/memfd.h>
#endif #endif
#ifdef HAVE_SYS_SIGNALFD_H
#include <sys/signalfd.h>
#endif
typedef int32_t key_serial_t; typedef int32_t key_serial_t;
#if !HAVE_KEYCTL #if !HAVE_KEYCTL
...@@ -155,6 +160,81 @@ static inline int setns(int fd, int nstype) ...@@ -155,6 +160,81 @@ static inline int setns(int fd, int nstype)
} }
#endif #endif
#ifndef HAVE_SYS_SIGNALFD_H
struct signalfd_siginfo {
uint32_t ssi_signo;
int32_t ssi_errno;
int32_t ssi_code;
uint32_t ssi_pid;
uint32_t ssi_uid;
int32_t ssi_fd;
uint32_t ssi_tid;
uint32_t ssi_band;
uint32_t ssi_overrun;
uint32_t ssi_trapno;
int32_t ssi_status;
int32_t ssi_int;
uint64_t ssi_ptr;
uint64_t ssi_utime;
uint64_t ssi_stime;
uint64_t ssi_addr;
uint8_t __pad[48];
};
#ifndef __NR_signalfd4
/* assume kernel headers are too old */
#if __i386__
#define __NR_signalfd4 327
#elif __x86_64__
#define __NR_signalfd4 289
#elif __powerpc__
#define __NR_signalfd4 313
#elif __s390x__
#define __NR_signalfd4 322
#elif __arm__
#define __NR_signalfd4 355
#elif __mips__ && _MIPS_SIM == _ABIO32
#define __NR_signalfd4 4324
#elif __mips__ && _MIPS_SIM == _ABI64
#define __NR_signalfd4 5283
#elif __mips__ && _MIPS_SIM == _ABIN32
#define __NR_signalfd4 6287
#endif
#endif
#ifndef __NR_signalfd
/* assume kernel headers are too old */
#if __i386__
#define __NR_signalfd 321
#elif __x86_64__
#define __NR_signalfd 282
#elif __powerpc__
#define __NR_signalfd 305
#elif __s390x__
#define __NR_signalfd 316
#elif __arm__
#define __NR_signalfd 349
#elif __mips__ && _MIPS_SIM == _ABIO32
#define __NR_signalfd 4317
#elif __mips__ && _MIPS_SIM == _ABI64
#define __NR_signalfd 5276
#elif __mips__ && _MIPS_SIM == _ABIN32
#define __NR_signalfd 6280
#endif
#endif
static inline int signalfd(int fd, const sigset_t *mask, int flags)
{
int retval;
retval = syscall(__NR_signalfd4, fd, mask, _NSIG / 8, flags);
if (errno == ENOSYS && flags == 0)
retval = syscall(__NR_signalfd, fd, mask, _NSIG / 8);
return retval;
}
#endif
/* Define unshare() if missing from the C library */ /* Define unshare() if missing from the C library */
#ifndef HAVE_UNSHARE #ifndef HAVE_UNSHARE
static inline int unshare(int flags) static inline int unshare(int flags)
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "lxclock.h" #include "lxclock.h"
#include "mainloop.h" #include "mainloop.h"
#include "start.h" #include "start.h"
#include "syscall_wrappers.h"
#include "terminal.h" #include "terminal.h"
#include "utils.h" #include "utils.h"
......
...@@ -56,86 +56,6 @@ extern char *get_rundir(void); ...@@ -56,86 +56,6 @@ extern char *get_rundir(void);
#endif #endif
#endif #endif
/* Define signalfd() if missing from the C library */
#ifdef HAVE_SYS_SIGNALFD_H
# include <sys/signalfd.h>
#else
/* assume kernel headers are too old */
#include <stdint.h>
struct signalfd_siginfo
{
uint32_t ssi_signo;
int32_t ssi_errno;
int32_t ssi_code;
uint32_t ssi_pid;
uint32_t ssi_uid;
int32_t ssi_fd;
uint32_t ssi_tid;
uint32_t ssi_band;
uint32_t ssi_overrun;
uint32_t ssi_trapno;
int32_t ssi_status;
int32_t ssi_int;
uint64_t ssi_ptr;
uint64_t ssi_utime;
uint64_t ssi_stime;
uint64_t ssi_addr;
uint8_t __pad[48];
};
# ifndef __NR_signalfd4
/* assume kernel headers are too old */
# if __i386__
# define __NR_signalfd4 327
# elif __x86_64__
# define __NR_signalfd4 289
# elif __powerpc__
# define __NR_signalfd4 313
# elif __s390x__
# define __NR_signalfd4 322
# elif __arm__
# define __NR_signalfd4 355
# elif __mips__ && _MIPS_SIM == _ABIO32
# define __NR_signalfd4 4324
# elif __mips__ && _MIPS_SIM == _ABI64
# define __NR_signalfd4 5283
# elif __mips__ && _MIPS_SIM == _ABIN32
# define __NR_signalfd4 6287
# endif
#endif
# ifndef __NR_signalfd
/* assume kernel headers are too old */
# if __i386__
# define __NR_signalfd 321
# elif __x86_64__
# define __NR_signalfd 282
# elif __powerpc__
# define __NR_signalfd 305
# elif __s390x__
# define __NR_signalfd 316
# elif __arm__
# define __NR_signalfd 349
# elif __mips__ && _MIPS_SIM == _ABIO32
# define __NR_signalfd 4317
# elif __mips__ && _MIPS_SIM == _ABI64
# define __NR_signalfd 5276
# elif __mips__ && _MIPS_SIM == _ABIN32
# define __NR_signalfd 6280
# endif
#endif
static inline int signalfd(int fd, const sigset_t *mask, int flags)
{
int retval;
retval = syscall (__NR_signalfd4, fd, mask, _NSIG / 8, flags);
if (errno == ENOSYS && flags == 0)
retval = syscall (__NR_signalfd, fd, mask, _NSIG / 8);
return retval;
}
#endif
static inline int lxc_set_cloexec(int fd) static inline int lxc_set_cloexec(int fd)
{ {
return fcntl(fd, F_SETFD, FD_CLOEXEC); return fcntl(fd, F_SETFD, FD_CLOEXEC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment