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

2014-02-21 Thread Lennart Poettering
On Fri, 21.02.14 08:28, Holger Schurig (holgerschu...@gmail.com) wrote:

 
 Compilation works okay here. And make check said PASS: test-namespace.
 
  The change I made is to complain if __NR_setns is not defined.
 
 The approach with an error message (at runtime) was taken from
 iproute2. I used that because for many (desktop) users namespace
 support isn't really needed. So if the libc would really not provide
 it, ... who cares. Then just the namespace related units wouldn't
 work, and they are not central to system bringup.

The behaviour is not too different now, it's now just the kernel that
returns ENOSYS, not userspace. Since setns() has been added in kernel
3.0 (which is the minimum kernel we require) it sounds sensible to
simply define the syscall number

 I didn't knew the syscall numbers differs between architectures. It
 never occured to me that this could be a sane design :-)

It's entirely moronic. It gets even worse when you notice the x86
madness that is socketcall(), where they decided to multiplex all socket
system calls through a single meta-syscall, just because. 

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2014-02-20 Thread Lennart Poettering
On Thu, 20.02.14 14:39, Holger Schurig (holgerschu...@gmail.com) wrote:

 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.

I modified your patch and commited it. The change I made is to complain
if __NR_setns is not defined. I also added the right definitions for the
two x86 archs in. Please test if things work now for you.

 ---
  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


Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2014-02-20 Thread Holger Schurig
Compilation works okay here. And make check said PASS: test-namespace.

 The change I made is to complain if __NR_setns is not defined.

The approach with an error message (at runtime) was taken from
iproute2. I used that because for many (desktop) users namespace
support isn't really needed. So if the libc would really not provide
it, ... who cares. Then just the namespace related units wouldn't
work, and they are not central to system bringup.

I didn't knew the syscall numbers differs between architectures. It
never occured to me that this could be a sane design :-)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2014-02-20 Thread Holger Schurig
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

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel