]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
iproute2: Auto-detect the presence of setns in libc
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 15 Jul 2011 14:26:59 +0000 (14:26 +0000)
committerStephen Hemminger <shemminger@vyatta.com>
Wed, 31 Aug 2011 18:02:02 +0000 (11:02 -0700)
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
ip/Makefile
ip/ipnetns.c

index 0795df85166a3ec6a16b722ae4063345d4892943..f5c3d405727efefec595041ad6a8d8cb41f1209a 100755 (executable)
--- a/configure
+++ b/configure
@@ -158,6 +158,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"
@@ -173,3 +194,6 @@ check_ipt
 
 echo -n "iptables modules directory: "
 check_ipt_lib_dir
+
+echo -n "libc has setns: "
+check_setns
index 2ee4e7c066009f181ca90f40c809dc0a0920c3f9..8d039934a71b07c1a7b531c3936db601a3d3554c 100644 (file)
@@ -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
index db7007cfde3a0a260814b8d42f6fa51da4185d78..dff3497aa598d6740ec3199eaba77201c8e1e3d5 100644 (file)
@@ -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)