From ee697391d6031f4d533db39ba5d2dd45758ac53b Mon Sep 17 00:00:00 2001 From: WANG Chao Date: Thu, 3 Dec 2015 13:54:36 +0800 Subject: [PATCH] define setns syscall wrapper to fix build issue For example on centos6.x, glibc doesn't contain setns syscall wrapper, but kernel has setns. We can write a wrapper to simulate the glibc behavior to fix compile issue. NOTE: In such case, we will need kernel-headers to get syscall number. Signed-off-by: WANG Chao --- src/container.c | 1 + src/exec.c | 2 +- src/init.c | 1 + src/syscall.h | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/syscall.h diff --git a/src/container.c b/src/container.c index 60c678c6..afccdbd6 100644 --- a/src/container.c +++ b/src/container.c @@ -17,6 +17,7 @@ #include "util.h" #include "hyper.h" #include "parse.h" +#include "syscall.h" static int container_setup_volume(struct hyper_container *container) { diff --git a/src/exec.c b/src/exec.c index 029e4820..1fa18ecb 100644 --- a/src/exec.c +++ b/src/exec.c @@ -12,11 +12,11 @@ #include #include #include -#include "syscall.h" #include "hyper.h" #include "util.h" #include "parse.h" +#include "syscall.h" static void pts_hup(struct hyper_event *de, int efd, int out) { diff --git a/src/init.c b/src/init.c index e7c75b9e..89252783 100644 --- a/src/init.c +++ b/src/init.c @@ -27,6 +27,7 @@ #include "event.h" #include "parse.h" #include "container.h" +#include "syscall.h" struct hyper_pod global_pod = { .containers = LIST_HEAD_INIT(global_pod.containers), diff --git a/src/syscall.h b/src/syscall.h new file mode 100644 index 00000000..4e337294 --- /dev/null +++ b/src/syscall.h @@ -0,0 +1,16 @@ +#define _GNU_SOURCE +#include +#include + +/* + * Use raw syscall for versions of glibc that don't include it. But this + * requires kernel-headers for syscall number hint. + */ + +#if !defined SYS_setns && defined __NR_setns +static inline int setns(int fd, int nstype) +{ + errno = syscall(__NR_setns, fd, nstype); + return errno == 0 ? 0 : -1; +} +#endif