chiark / gitweb /
build-sys: Add setns() functions if not in the C library.
authorHolger Schurig <holgerschurig@gmail.com>
Thu, 20 Feb 2014 13:39:13 +0000 (14:39 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 21 Feb 2014 02:06:29 +0000 (03:06 +0100)
Debian Stable is still using glibc 2.13, which doesn't provide the setns().
So we detect this and provide a tiny wrapper that issues the setns syscall
towards the kernel.

configure.ac
src/shared/missing.h

index 05ee098d2827c9549c7fe5860ddc66966db8532d..18df6d86e7e9d1229bd55c6af5b40181fe56eb70 100644 (file)
@@ -241,10 +241,11 @@ LIBS="$save_LIBS"
 
 AC_CHECK_FUNCS([fanotify_init fanotify_mark])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
 
 AC_CHECK_FUNCS([fanotify_init fanotify_mark])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
-AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at], [], [], [[#include <sys/types.h>
+AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at, setns], [], [], [[#include <sys/types.h>
 #include <unistd.h>
 #include <sys/mount.h>
 #include <unistd.h>
 #include <sys/mount.h>
-#include <fcntl.h>]])
+#include <fcntl.h>
+#include <sched.h>]])
 
 # This makes sure pkg.m4 is available.
 m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
 
 # This makes sure pkg.m4 is available.
 m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
index 2661285a227c39fb3d8f181fbbee960aac90ee31..3142306e35c2375382c2539ea81787cb674d4ad9 100644 (file)
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 #include <linux/oom.h>
 #include <linux/input.h>
 #include <linux/if_link.h>
 #include <linux/oom.h>
 #include <linux/input.h>
 #include <linux/if_link.h>
@@ -353,3 +354,19 @@ static inline int name_to_handle_at(int fd, const char *name, struct file_handle
 #endif
 
 #endif
 #endif
 
 #endif
+
+#ifndef __NR_setns
+#  if defined(__x86_64__)
+#    define __NR_setns 308
+#  elif defined(__i386__)
+#    define __NR_setns 346
+#  else
+#    error "__NR_setns is not defined"
+#  endif
+#endif
+
+#if !HAVE_DECL_SETNS
+static inline int setns(int fd, int nstype) {
+        return syscall(__NR_setns, fd, nstype);
+}
+#endif