--- /dev/null
+From fc111c5df2ce573f6d01c2a78405455aa4bc766c Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+Date: Wed, 16 Mar 2016 11:47:51 +0100
+Subject: [PATCH] src/lxc/utils.h: don't redefine setns()
+
+The current logic in src/lxc/utils.h consists in implementing a
+setns() function if HAVE_SETNS is undefined. However, there are cases
+where the autoconf setns() check will fail (and therefore HAVE_SETNS
+will not be defined), but the C library does provide a setns()
+prototype. Unfortunately, this prototype conflicts with the one used
+internally in LXC. The C library headers define:
+
+extern int setns (int __fd, int __nstype) __THROW;
+
+While LXC defines:
+
+static inline int do_setns(int fd, int nstype)
+
+Which triggers the following build failures:
+
+utils.h:52:19: error: static declaration of 'setns' follows non-static declaration
+ static inline int setns(int fd, int nstype)
+ ^
+In file included from /home/test/buildroot2/output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include/sched.h:43:0,
+ from bdev.c:38:
+/home/test/buildroot2/output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include/bits/sched.h:91:12: note: previous declaration of 'setns' was here
+ extern int setns (int __fd, int __nstype) __THROW;
+
+In order to resolve this problem, we adopt the solution that was
+adopted by the gdb project at
+https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=a8c636cb54328fb9a71dcf27b66a7e7ab5443d88:
+the function defined by LXC is renamed to do_setns(), and calls
+setns() when available, or otherwise falls back on doing the system
+calls manually.
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+---
+ src/lxc/attach.c | 2 +-
+ src/lxc/conf.c | 4 ++--
+ src/lxc/lxc_user_nic.c | 4 ++--
+ src/lxc/start.c | 2 +-
+ src/lxc/utils.c | 2 +-
+ src/lxc/utils.h | 9 ++++-----
+ 6 files changed, 11 insertions(+), 12 deletions(-)
+
+diff --git a/src/lxc/attach.c b/src/lxc/attach.c
+index 436ae7a..953963f 100644
+--- a/src/lxc/attach.c
++++ b/src/lxc/attach.c
+@@ -260,7 +260,7 @@ static int lxc_attach_to_ns(pid_t pid, int which)
+ }
+
+ for (i = 0; i < size; i++) {
+- if (fd[i] >= 0 && setns(fd[i], 0) != 0) {
++ if (fd[i] >= 0 && do_setns(fd[i], 0) != 0) {
+ saved_errno = errno;
+
+ for (j = i; j < size; j++)
+diff --git a/src/lxc/conf.c b/src/lxc/conf.c
+index 55c2fae..8c7f16f 100644
+--- a/src/lxc/conf.c
++++ b/src/lxc/conf.c
+@@ -2636,7 +2636,7 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
+ SYSERROR("Failed to open monitor netns fd");
+ return;
+ }
+- if (setns(netnsfd, 0) != 0) {
++ if (do_setns(netnsfd, 0) != 0) {
+ SYSERROR("Failed to enter container netns to reset nics");
+ close(oldfd);
+ return;
+@@ -2647,7 +2647,7 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
+ WARN("Error moving nic index:%d back to host netns",
+ s->ifindex);
+ }
+- if (setns(oldfd, 0) != 0)
++ if (do_setns(oldfd, 0) != 0)
+ SYSERROR("Failed to re-enter monitor's netns");
+ close(oldfd);
+ }
+diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c
+index 6622db0..399e855 100644
+--- a/src/lxc/lxc_user_nic.c
++++ b/src/lxc/lxc_user_nic.c
+@@ -492,7 +492,7 @@ static int rename_in_ns(int pid, char *oldname, char **newnamep)
+ fprintf(stderr, "Opening %s\n", nspath);
+ goto out_err;
+ }
+- if (setns(fd, 0) < 0) {
++ if (do_setns(fd, 0) < 0) {
+ fprintf(stderr, "setns to container network namespace\n");
+ goto out_err;
+ }
+@@ -519,7 +519,7 @@ static int rename_in_ns(int pid, char *oldname, char **newnamep)
+ if (!*newnamep)
+ goto out_err;
+ }
+- if (setns(ofd, 0) < 0) {
++ if (do_setns(ofd, 0) < 0) {
+ fprintf(stderr, "Error returning to original netns\n");
+ close(ofd);
+ return -1;
+diff --git a/src/lxc/start.c b/src/lxc/start.c
+index fa905e2..2c76713 100644
+--- a/src/lxc/start.c
++++ b/src/lxc/start.c
+@@ -157,7 +157,7 @@ static int attach_ns(const int ns_fd[LXC_NS_MAX]) {
+ if (ns_fd[i] < 0)
+ continue;
+
+- if (setns(ns_fd[i], 0) != 0)
++ if (do_setns(ns_fd[i], 0) != 0)
+ goto error;
+ }
+ return 0;
+diff --git a/src/lxc/utils.c b/src/lxc/utils.c
+index d9e769d..a696e0f 100644
+--- a/src/lxc/utils.c
++++ b/src/lxc/utils.c
+@@ -1091,7 +1091,7 @@ bool switch_to_ns(pid_t pid, const char *ns) {
+ return false;
+ }
+
+- ret = setns(fd, 0);
++ ret = do_setns(fd, 0);
+ if (ret) {
+ SYSERROR("failed to set process %d to %s of %d.", pid, ns, fd);
+ close(fd);
+diff --git a/src/lxc/utils.h b/src/lxc/utils.h
+index 059026f..0f79ba0 100644
+--- a/src/lxc/utils.h
++++ b/src/lxc/utils.h
+@@ -47,11 +47,11 @@ extern char *get_rundir(void);
+ #endif
+ #endif
+
+-/* Define setns() if missing from the C library */
+-#ifndef HAVE_SETNS
+-static inline int setns(int fd, int nstype)
++static inline int do_setns(int fd, int nstype)
+ {
+-#ifdef __NR_setns
++#ifdef HAVE_SETNS
++ return setns(fd, nstype);
++#elif defined(__NR_setns)
+ return syscall(__NR_setns, fd, nstype);
+ #elif defined(__NR_set_ns)
+ return syscall(__NR_set_ns, fd, nstype);
+@@ -60,7 +60,6 @@ static inline int setns(int fd, int nstype)
+ return -1;
+ #endif
+ }
+-#endif
+
+ /* Define unshare() if missing from the C library */
+ #ifndef HAVE_UNSHARE
+--
+2.6.4
+