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

Lennart Poettering lennart at poettering.net
Thu Feb 20 18:09:15 PST 2014


On Thu, 20.02.14 14:39, Holger Schurig (holgerschurig at 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


More information about the systemd-devel mailing list