From: ebiederm@xmission.com (Eric W. Biederman)
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: <netdev@vger.kernel.org>, Dan McGee <dan@archlinux.org>
Subject: [PATCH] iproute2: Auto-detect the presence of setns in libc
Date: Fri, 15 Jul 2011 17:26:59 -0700 [thread overview]
Message-ID: <m1mxgfkr3g.fsf@fess.ebiederm.org> (raw)
If libc has setns present use that version instead of
rolling the syscall wrapper by hand.
Dan McGee found the following compile error:
gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include
-DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib/\" -c -o ipnetns.o ipnetns.c
ipnetns.c:31:12: error: static declaration of ‘setns’ follows non-static
declaration
/usr/include/bits/sched.h:93:12: note: previous declaration of ‘setns’
was here
make[1]: *** [ipnetns.o] Error 1
Reported-by: Dan McGee <dan@archlinux.org>
Tested-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
configure | 24 ++++++++++++++++++++++++
ip/Makefile | 6 ++++++
ip/ipnetns.c | 2 ++
3 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 69797ab..cfcc82a 100755
--- a/configure
+++ b/configure
@@ -163,6 +163,27 @@ check_ipt_lib_dir()
echo "not found!"
}
+check_setns()
+{
+cat >/tmp/setnstest.c <<EOF
+#include <sched.h>
+int main(int argc, char **argv)
+{
+ (void)setns(0,0);
+ return 0;
+}
+EOF
+gcc -I$INCLUDE -o /tmp/setnstest /tmp/setnstest.c >/dev/null 2>&1
+if [ $? -eq 0 ]
+then
+ echo "IP_CONFIG_SETNS:=y" >>Config
+ echo "yes"
+else
+ echo "no"
+fi
+rm -f /tmp/setnstest.c /tmp/setnstest
+}
+
echo "# Generated config based on" $INCLUDE >Config
echo "TC schedulers"
@@ -178,3 +199,6 @@ check_ipt
echo -n "iptables modules directory: "
check_ipt_lib_dir
+
+echo -n "libc has setns: "
+check_setns
diff --git a/ip/Makefile b/ip/Makefile
index 2ee4e7c..8d03993 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -7,6 +7,12 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
RTMONOBJ=rtmon.o
+include ../Config
+
+ifeq ($(IP_CONFIG_SETNS),y)
+ CFLAGS += -DHAVE_SETNS
+endif
+
ALLOBJ=$(IPOBJ) $(RTMONOBJ)
SCRIPTS=ifcfg rtpr routel routef
TARGETS=ip rtmon
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index db7007c..dff3497 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -28,6 +28,7 @@
#define MNT_DETACH 0x00000002 /* Just detach from the tree */
#endif /* MNT_DETACH */
+#ifndef HAVE_SETNS
static int setns(int fd, int nstype)
{
#ifdef __NR_setns
@@ -37,6 +38,7 @@ static int setns(int fd, int nstype)
return -1;
#endif
}
+#endif /* HAVE_SETNS */
static int touch(const char *path, mode_t mode)
--
1.7.5.1.217.g4e3aa
next reply other threads:[~2011-07-16 0:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-16 0:26 Eric W. Biederman [this message]
2011-07-16 0:34 ` [PATCH] iproute2: Auto-detect the presence of setns in libc Dan McGee
2011-07-20 22:16 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1mxgfkr3g.fsf@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=dan@archlinux.org \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox