[systemd-devel] [PATCH] Add setns() functions if not in the C library.

Holger Schurig holgerschurig at gmail.com
Thu Feb 20 05:39:13 PST 2014


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         |    3 +++
 src/shared/missing.h |   13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/configure.ac b/configure.ac
index 05ee098..40162ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -250,6 +250,9 @@ AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at], [], [], [[#include <sys/
 m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
 
 # ------------------------------------------------------------------------------
+AC_CHECK_FUNCS([setns])
+
+# ------------------------------------------------------------------------------
 have_dbus=no
 AC_ARG_ENABLE(dbus, AS_HELP_STRING([--disable-dbus], [disable usage of dbus-1 in tests]))
 AS_IF([test "x$enable_dbus" != "xno"], [
diff --git a/src/shared/missing.h b/src/shared/missing.h
index 2661285..ea87053 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -28,6 +28,7 @@
 #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>
@@ -352,4 +353,16 @@ static inline int name_to_handle_at(int fd, const char *name, struct file_handle
 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
 #endif
 
+#ifndef HAVE_SETNS
+static inline int setns(int fd, int nstype)
+{
+#ifdef __NR_setns
+        return syscall(__NR_setns, fd, nstype);
+#else
+        errno = ENOSYS;
+        return -1;
+#endif
+}
+#endif
+
 #endif
-- 
1.7.10.4



More information about the systemd-devel mailing list