From 909b91a32782d12ac88c4467a390915836feae6d Mon Sep 17 00:00:00 2001 From: "faicker.mo" Date: Fri, 7 Apr 2017 18:35:13 +0800 Subject: [PATCH] Support glibc version<2.14 without setns api(centos6) --- src/netns.h | 15 +++++++++++++++ src/posix.cc | 1 + 2 files changed, 16 insertions(+) create mode 100644 src/netns.h diff --git a/src/netns.h b/src/netns.h new file mode 100644 index 0000000..25d6cdf --- /dev/null +++ b/src/netns.h @@ -0,0 +1,15 @@ +#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 14 +/* Define setns() if missing from the C library */ +#include +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 diff --git a/src/posix.cc b/src/posix.cc index 974c5f7..fd09d18 100644 --- a/src/posix.cc +++ b/src/posix.cc @@ -24,6 +24,7 @@ #include #include "./exc.h" +#include "./netns.h" namespace pyflame { int OpenRdonly(const char *path) {