[lxc-devel] [lxc/master] syscalls: move wrappers and raw syscalls to appropriate files

brauner on Github lxc-bot at linuxcontainers.org
Wed Oct 3 11:12:09 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181003/f2c2d15a/attachment.bin>
-------------- next part --------------
From 6a886ddf192885d6896f4f67cc94df8b68fbc560 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 12:49:46 +0200
Subject: [PATCH 1/6] syscall_wrappers: move memfd_create()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/ringbuf.c          |  1 +
 src/lxc/syscall_wrappers.h | 48 ++++++++++++++++++++++++++++++++++++++
 src/lxc/utils.h            | 48 --------------------------------------
 3 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/src/lxc/ringbuf.c b/src/lxc/ringbuf.c
index 1d5cfe916..97f68539f 100644
--- a/src/lxc/ringbuf.c
+++ b/src/lxc/ringbuf.c
@@ -32,6 +32,7 @@
 
 #include "config.h"
 #include "ringbuf.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
index a6c7694d9..da376d589 100644
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -32,6 +32,10 @@
 
 #include "config.h"
 
+#ifdef HAVE_LINUX_MEMFD_H
+#include <linux/memfd.h>
+#endif
+
 typedef int32_t key_serial_t;
 
 #if !HAVE_KEYCTL
@@ -48,6 +52,50 @@ static inline long __keyctl(int cmd, unsigned long arg2, unsigned long arg3,
 #define keyctl __keyctl
 #endif
 
+#ifndef HAVE_MEMFD_CREATE
+static inline int memfd_create(const char *name, unsigned int flags) {
+	#ifndef __NR_memfd_create
+		#if defined __i386__
+			#define __NR_memfd_create 356
+		#elif defined __x86_64__
+			#define __NR_memfd_create 319
+		#elif defined __arm__
+			#define __NR_memfd_create 385
+		#elif defined __aarch64__
+			#define __NR_memfd_create 279
+		#elif defined __s390__
+			#define __NR_memfd_create 350
+		#elif defined __powerpc__
+			#define __NR_memfd_create 360
+		#elif defined __sparc__
+			#define __NR_memfd_create 348
+		#elif defined __blackfin__
+			#define __NR_memfd_create 390
+		#elif defined __ia64__
+			#define __NR_memfd_create 1340
+		#elif defined _MIPS_SIM
+			#if _MIPS_SIM == _MIPS_SIM_ABI32
+				#define __NR_memfd_create 4354
+			#endif
+			#if _MIPS_SIM == _MIPS_SIM_NABI32
+				#define __NR_memfd_create 6318
+			#endif
+			#if _MIPS_SIM == _MIPS_SIM_ABI64
+				#define __NR_memfd_create 5314
+			#endif
+		#endif
+	#endif
+	#ifdef __NR_memfd_create
+	return syscall(__NR_memfd_create, name, flags);
+	#else
+	errno = ENOSYS;
+	return -1;
+	#endif
+}
+#else
+extern int memfd_create(const char *name, unsigned int flags);
+#endif
+
 #if !HAVE_PIVOT_ROOT
 static int pivot_root(const char *new_root, const char *put_old)
 {
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 7bb361cfb..8c5914de7 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -43,10 +43,6 @@
 #include "raw_syscalls.h"
 #include "string_utils.h"
 
-#ifdef HAVE_LINUX_MEMFD_H
-#include <linux/memfd.h>
-#endif
-
 /* returns 1 on success, 0 if there were any failures */
 extern int lxc_rmdir_onedev(const char *path, const char *exclude);
 extern int get_u16(unsigned short *val, const char *arg, int base);
@@ -199,50 +195,6 @@ static inline int signalfd(int fd, const sigset_t *mask, int flags)
 }
 #endif
 
-#ifndef HAVE_MEMFD_CREATE
-static inline int memfd_create(const char *name, unsigned int flags) {
-	#ifndef __NR_memfd_create
-		#if defined __i386__
-			#define __NR_memfd_create 356
-		#elif defined __x86_64__
-			#define __NR_memfd_create 319
-		#elif defined __arm__
-			#define __NR_memfd_create 385
-		#elif defined __aarch64__
-			#define __NR_memfd_create 279
-		#elif defined __s390__
-			#define __NR_memfd_create 350
-		#elif defined __powerpc__
-			#define __NR_memfd_create 360
-		#elif defined __sparc__
-			#define __NR_memfd_create 348
-		#elif defined __blackfin__
-			#define __NR_memfd_create 390
-		#elif defined __ia64__
-			#define __NR_memfd_create 1340
-		#elif defined _MIPS_SIM
-			#if _MIPS_SIM == _MIPS_SIM_ABI32
-				#define __NR_memfd_create 4354
-			#endif
-			#if _MIPS_SIM == _MIPS_SIM_NABI32
-				#define __NR_memfd_create 6318
-			#endif
-			#if _MIPS_SIM == _MIPS_SIM_ABI64
-				#define __NR_memfd_create 5314
-			#endif
-		#endif
-	#endif
-	#ifdef __NR_memfd_create
-	return syscall(__NR_memfd_create, name, flags);
-	#else
-	errno = ENOSYS;
-	return -1;
-	#endif
-}
-#else
-extern int memfd_create(const char *name, unsigned int flags);
-#endif
-
 static inline int lxc_set_cloexec(int fd)
 {
 	return fcntl(fd, F_SETFD, FD_CLOEXEC);

From 59524108dd4342f2c99d8faac8145ab0c3c0208e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 12:57:32 +0200
Subject: [PATCH 2/6] syscall_wrappers: move setns()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/Makefile.am        |  3 ++-
 src/lxc/attach.c           |  1 +
 src/lxc/cmd/lxc_user_nic.c |  1 +
 src/lxc/network.c          |  1 +
 src/lxc/start.c            |  1 +
 src/lxc/syscall_wrappers.h | 32 ++++++++++++++++++++++++++++++++
 src/lxc/utils.h            | 31 -------------------------------
 7 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 2011a6c02..208a485e1 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -360,7 +360,8 @@ lxc_user_nic_SOURCES = cmd/lxc_user_nic.c \
 		       log.c log.h \
 		       network.c network.h \
 		       parse.c parse.h \
-		       raw_syscalls.c raw_syscalls.h
+		       raw_syscalls.c raw_syscalls.h \
+		       syscall_wrappers.h
 lxc_usernsexec_SOURCES = cmd/lxc_usernsexec.c \
 			 conf.c conf.h \
 			 list.h \
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 437001079..689cef709 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -60,6 +60,7 @@
 #include "mainloop.h"
 #include "namespace.h"
 #include "raw_syscalls.h"
+#include "syscall_wrappers.h"
 #include "terminal.h"
 #include "utils.h"
 
diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index 6d7011136..02915b882 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -52,6 +52,7 @@
 #include "network.h"
 #include "parse.h"
 #include "raw_syscalls.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 #ifndef HAVE_STRLCPY
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 3ed35afd4..df1989272 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -57,6 +57,7 @@
 #include "network.h"
 #include "nl.h"
 #include "raw_syscalls.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 #ifndef HAVE_STRLCPY
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 5899ea07b..178067042 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -75,6 +75,7 @@
 #include "storage/storage.h"
 #include "storage/storage_utils.h"
 #include "sync.h"
+#include "syscall_wrappers.h"
 #include "terminal.h"
 #include "utils.h"
 
diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
index da376d589..b83ff6829 100644
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -25,6 +25,7 @@
 #endif
 #include <asm/unistd.h>
 #include <linux/keyctl.h>
+#include <sched.h>
 #include <stdint.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
@@ -110,4 +111,35 @@ static int pivot_root(const char *new_root, const char *put_old)
 extern int pivot_root(const char *new_root, const char *put_old);
 #endif
 
+#if !defined(__NR_setns) && !defined(__NR_set_ns)
+	#if defined(__x86_64__)
+		#define __NR_setns 308
+	#elif defined(__i386__)
+		#define __NR_setns 346
+	#elif defined(__arm__)
+		#define __NR_setns 375
+	#elif defined(__aarch64__)
+		#define __NR_setns 375
+	#elif defined(__powerpc__)
+		#define __NR_setns 350
+	#elif defined(__s390__)
+		#define __NR_setns 339
+	#endif
+#endif
+
+/* Define setns() if missing from the C library */
+#ifndef HAVE_SETNS
+static inline int setns(int fd, int nstype)
+{
+#ifdef __NR_setns
+	return syscall(__NR_setns, fd, nstype);
+#elif defined(__NR_set_ns)
+	return syscall(__NR_set_ns, fd, nstype);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+#endif
+
 #endif /* __LXC_SYSCALL_WRAPPER_H */
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 8c5914de7..5e70dec1a 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -56,37 +56,6 @@ extern char *get_rundir(void);
 #endif
 #endif
 
-#if !defined(__NR_setns) && !defined(__NR_set_ns)
-	#if defined(__x86_64__)
-		#define __NR_setns 308
-	#elif defined(__i386__)
-		#define __NR_setns 346
-	#elif defined(__arm__)
-		#define __NR_setns 375
-	#elif defined(__aarch64__)
-		#define __NR_setns 375
-	#elif defined(__powerpc__)
-		#define __NR_setns 350
-	#elif defined(__s390__)
-		#define __NR_setns 339
-	#endif
-#endif
-
-/* Define setns() if missing from the C library */
-#ifndef HAVE_SETNS
-static inline int setns(int fd, int nstype)
-{
-#ifdef __NR_setns
-	return syscall(__NR_setns, fd, nstype);
-#elif defined(__NR_set_ns)
-	return syscall(__NR_set_ns, fd, nstype);
-#else
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-#endif
-
 /* Define sethostname() if missing from the C library */
 #ifndef HAVE_SETHOSTNAME
 static inline int sethostname(const char *name, size_t len)

From 364932cfae36feda321d20574ce25c12519b0f54 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 12:59:32 +0200
Subject: [PATCH 3/6] syscall_wrappers: move sethostname()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/syscall_wrappers.h | 13 +++++++++++++
 src/lxc/utils.h            | 13 -------------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
index b83ff6829..c2cebe6a8 100644
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -127,6 +127,19 @@ extern int pivot_root(const char *new_root, const char *put_old);
 	#endif
 #endif
 
+/* Define sethostname() if missing from the C library */
+#ifndef HAVE_SETHOSTNAME
+static inline int sethostname(const char *name, size_t len)
+{
+#ifdef __NR_sethostname
+	return syscall(__NR_sethostname, name, len);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+#endif
+
 /* Define setns() if missing from the C library */
 #ifndef HAVE_SETNS
 static inline int setns(int fd, int nstype)
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 5e70dec1a..ee3875e58 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -56,19 +56,6 @@ extern char *get_rundir(void);
 #endif
 #endif
 
-/* Define sethostname() if missing from the C library */
-#ifndef HAVE_SETHOSTNAME
-static inline int sethostname(const char *name, size_t len)
-{
-#ifdef __NR_sethostname
-return syscall(__NR_sethostname, name, len);
-#else
-errno = ENOSYS;
-return -1;
-#endif
-}
-#endif
-
 /* Define unshare() if missing from the C library */
 #ifndef HAVE_UNSHARE
 static inline int unshare(int flags)

From e8f764b6bc74eefa31fe7e029cc7ce09f1f09471 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 13:03:30 +0200
Subject: [PATCH 4/6] syscall_wrappers: move unshare()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/Makefile.am             |  1 +
 src/lxc/cmd/lxc_usernsexec.c    |  1 +
 src/lxc/criu.c                  |  1 +
 src/lxc/lxccontainer.c          |  1 +
 src/lxc/storage/rsync.c         |  1 +
 src/lxc/storage/storage_utils.c |  1 +
 src/lxc/syscall_wrappers.h      | 15 +++++++++++++++
 src/lxc/utils.h                 | 15 ---------------
 8 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 208a485e1..5a0ae9dd4 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -369,6 +369,7 @@ lxc_usernsexec_SOURCES = cmd/lxc_usernsexec.c \
 			 macro.h \
 			 file_utils.c file_utils.h \
 			 string_utils.c string_utils.h \
+			 syscall_wrappers.h \
 			 utils.c utils.h
 endif
 
diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c
index 7475e7506..10557dd51 100644
--- a/src/lxc/cmd/lxc_usernsexec.c
+++ b/src/lxc/cmd/lxc_usernsexec.c
@@ -49,6 +49,7 @@
 #include "macro.h"
 #include "file_utils.h"
 #include "string_utils.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 extern int lxc_log_fd;
diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 66470a016..dcf6d5cf6 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -45,6 +45,7 @@
 #include "lxclock.h"
 #include "network.h"
 #include "storage.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 #if IS_BIONIC
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index b4cb4c0ad..bfd3c85a1 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -73,6 +73,7 @@
 #include "storage/overlay.h"
 #include "storage_utils.h"
 #include "sync.h"
+#include "syscall_wrappers.h"
 #include "terminal.h"
 #include "utils.h"
 #include "version.h"
diff --git a/src/lxc/storage/rsync.c b/src/lxc/storage/rsync.c
index e3ade30a0..fa4e59cc3 100644
--- a/src/lxc/storage/rsync.c
+++ b/src/lxc/storage/rsync.c
@@ -38,6 +38,7 @@
 #include "log.h"
 #include "rsync.h"
 #include "storage.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 lxc_log_define(rsync, lxc);
diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c
index 36a62a11e..9efc939b1 100644
--- a/src/lxc/storage/storage_utils.c
+++ b/src/lxc/storage/storage_utils.c
@@ -48,6 +48,7 @@
 #include "parse.h"
 #include "storage.h"
 #include "storage_utils.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 #ifndef HAVE_STRLCPY
diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
index c2cebe6a8..8661ceb4f 100644
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -155,4 +155,19 @@ static inline int setns(int fd, int nstype)
 }
 #endif
 
+/* Define unshare() if missing from the C library */
+#ifndef HAVE_UNSHARE
+static inline int unshare(int flags)
+{
+#ifdef __NR_unshare
+	return syscall(__NR_unshare, flags);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+#else
+extern int unshare(int);
+#endif
+
 #endif /* __LXC_SYSCALL_WRAPPER_H */
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index ee3875e58..5f16eaedb 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -56,21 +56,6 @@ extern char *get_rundir(void);
 #endif
 #endif
 
-/* Define unshare() if missing from the C library */
-#ifndef HAVE_UNSHARE
-static inline int unshare(int flags)
-{
-#ifdef __NR_unshare
-	return syscall(__NR_unshare, flags);
-#else
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-#else
-extern int unshare(int);
-#endif
-
 /* Define signalfd() if missing from the C library */
 #ifdef HAVE_SYS_SIGNALFD_H
 #  include <sys/signalfd.h>

From 303037d2f6793be350111180382d369a820f3bb6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 13:08:51 +0200
Subject: [PATCH 5/6] syscall_wrappers: move signalfd()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/storage/nbd.c      |  1 +
 src/lxc/syscall_wrappers.h | 80 ++++++++++++++++++++++++++++++++++++++
 src/lxc/terminal.c         |  1 +
 src/lxc/utils.h            | 80 --------------------------------------
 4 files changed, 82 insertions(+), 80 deletions(-)

diff --git a/src/lxc/storage/nbd.c b/src/lxc/storage/nbd.c
index cc2289426..2fae1fdb2 100644
--- a/src/lxc/storage/nbd.c
+++ b/src/lxc/storage/nbd.c
@@ -38,6 +38,7 @@
 #include "nbd.h"
 #include "storage.h"
 #include "storage_utils.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 #ifndef HAVE_STRLCPY
diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
index 8661ceb4f..42d94db28 100644
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -24,6 +24,7 @@
 #define _GNU_SOURCE 1
 #endif
 #include <asm/unistd.h>
+#include <errno.h>
 #include <linux/keyctl.h>
 #include <sched.h>
 #include <stdint.h>
@@ -37,6 +38,10 @@
 #include <linux/memfd.h>
 #endif
 
+#ifdef HAVE_SYS_SIGNALFD_H
+#include <sys/signalfd.h>
+#endif
+
 typedef int32_t key_serial_t;
 
 #if !HAVE_KEYCTL
@@ -155,6 +160,81 @@ static inline int setns(int fd, int nstype)
 }
 #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 */
 #ifndef HAVE_UNSHARE
 static inline int unshare(int flags)
diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index 03bd8983b..4060e7f9b 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -45,6 +45,7 @@
 #include "lxclock.h"
 #include "mainloop.h"
 #include "start.h"
+#include "syscall_wrappers.h"
 #include "terminal.h"
 #include "utils.h"
 
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 5f16eaedb..f7247a2d8 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -56,86 +56,6 @@ extern char *get_rundir(void);
 #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)
 {
 	return fcntl(fd, F_SETFD, FD_CLOEXEC);

From 07a50156ed3e8ffdd0c7736a581f8e82903d2c09 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Oct 2018 13:10:55 +0200
Subject: [PATCH 6/6] raw_syscalls: move lxc_raw_gettid()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/raw_syscalls.h | 9 +++++++++
 src/lxc/utils.h        | 9 ---------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/lxc/raw_syscalls.h b/src/lxc/raw_syscalls.h
index 513089649..224cf92fc 100644
--- a/src/lxc/raw_syscalls.h
+++ b/src/lxc/raw_syscalls.h
@@ -83,4 +83,13 @@ static inline pid_t lxc_raw_getpid(void)
 	return (pid_t)syscall(SYS_getpid);
 }
 
+static inline pid_t lxc_raw_gettid(void)
+{
+#ifdef __NR_gettid
+	return syscall(__NR_gettid);
+#else
+	return lxc_raw_getpid();
+#endif
+}
+
 #endif /* __LXC_RAW_SYSCALL_H */
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index f7247a2d8..bc298acc8 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -237,15 +237,6 @@ static inline uint64_t lxc_getpagesize(void)
  */
 extern uint64_t lxc_find_next_power2(uint64_t n);
 
-static inline pid_t lxc_raw_gettid(void)
-{
-#ifdef SYS_gettid
-	return syscall(SYS_gettid);
-#else
-	return lxc_raw_getpid();
-#endif
-}
-
 /* Set a signal the child process will receive after the parent has died. */
 extern int lxc_set_death_signal(int signal, pid_t parent);
 extern int fd_cloexec(int fd, bool cloexec);


More information about the lxc-devel mailing list