From 59524108dd4342f2c99d8faac8145ab0c3c0208e Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 3 Oct 2018 12:57:32 +0200 Subject: [PATCH] syscall_wrappers: move setns() Signed-off-by: Christian Brauner --- 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 #include +#include #include #include #include @@ -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) -- 2.39.5