Skip to contentSkip to conversation

util-linux: Add an option to compile 'nsenter' binary.

PATCH New Nicolas Cavallari 2 participants 6 messages Dec 23, 2014 – Dec 26, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

nsenter is a tool to enter the namespace of another process.

---
 package/util-linux/Config.in     | 5 +++++
 package/util-linux/util-linux.mk | 1 +
 2 files changed, 6 insertions(+)
package/util-linux/Config.in +5 -0
index 5dfd050..2f23419 100644
@@ -118,6 +118,11 @@ config BR2_PACKAGE_UTIL_LINUX_MESG
 	help
 	  Control write access to your terminal
 
+config BR2_PACKAGE_UTIL_LINUX_NSENTER
+	bool "nsenter"
+	help
+	  Enter the namespaces of another process.
+
 config BR2_PACKAGE_UTIL_LINUX_MOUNT
 	bool "mount/umount"
 	help
package/util-linux/util-linux.mk +1 -0
index e06fa9a..a530596 100644
@@ -74,6 +74,7 @@ UTIL_LINUX_CONF_OPTS += \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_LOGIN_UTILS),--enable-last --enable-login --enable-su --enable-sulogin,--disable-last --disable-login --disable-su --disable-sulogin) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_LOSETUP),--enable-losetup,--disable-losetup) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_MESG),--enable-mesg,--disable-mesg) \
+	$(if $(BR2_PACKAGE_UTIL_LINUX_NSENTER),--enable-nsenter,--disable-nsenter) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_MOUNT),--enable-mount,--disable-mount) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_NEWGRP),--enable-newgrp,--disable-newgrp) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX_PARTX),--enable-partx,--disable-partx) \
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

Dear Nicolas Cavallari,

Quoted 7 lines · Nicolas Cavallari

nsenter is a tool to enter the namespace of another process.

---
 package/util-linux/Config.in     | 5 +++++
 package/util-linux/util-linux.mk | 1 +
 2 files changed, 6 insertions(+)

We had this option in the past, but it was causing some problems with a number of toolchains, so we had to revert it. See:

http://git.buildroot.net/buildroot/commit/package/util-linux?id=d293e64bfb75c4cbaab7e46472de674ee813d4aa

Has this issue been resolved?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

Quoted 6 lines · Thomas Petazzoni

Dear Nicolas Cavallari,

We had this option in the past, but it was causing some problems with a number of toolchains, so we had to revert it. See:

http://git.buildroot.net/buildroot/commit/package/util-linux?id=d293e64bfb75c4cbaab7e46472de674ee813d4aa

I didn't know. It was compiling fine with uclibc. Now I realize that uclibc does not provide setns()...

Quoted 1 line

Has this issue been resolved?

Yes, there is a fallback in util-linux sources:

# if !defined(HAVE_SETNS) && defined(SYS_setns)
static inline int setns(int fd, int nstype)
{
        return syscall(SYS_setns, fd, nstype);
}
# endif
#3 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

In reply to Nicolas Cavallari

Dear Nicolas Cavallari,

Quoted 7 lines · Nicolas Cavallari

nsenter is a tool to enter the namespace of another process.

---
 package/util-linux/Config.in     | 5 +++++
 package/util-linux/util-linux.mk | 1 +
 2 files changed, 6 insertions(+)

Thanks, applied after adding a Config.in condition to make sure that we don't enable this option if we have kernel headers older than 3.0: the setns() system call was added in Linux 3.0.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

Quoted 11 lines · Thomas Petazzoni

Dear Nicolas Cavallari,

Quoted 7 lines · Nicolas Cavallari

nsenter is a tool to enter the namespace of another process.

---
 package/util-linux/Config.in     | 5 +++++
 package/util-linux/util-linux.mk | 1 +
 2 files changed, 6 insertions(+)
Quoted 3 lines

Thanks, applied after adding a Config.in condition to make sure that we don't enable this option if we have kernel headers older than 3.0: the setns() system call was added in Linux 3.0.

I'm not so sure now ... The fallback uses SYS_netns, instead of the kernel's __NR_setns, so i assume that there must be some C library support ... uclibc does define SYS_netns to be __NR_setns, so i think the problem is still valid if the toolchain does not define SYS_setns.

#5 lore raw

PATCH 1/1 util-linux: Add an option to compile 'nsenter' binary.

Dear Nicolas Cavallari,

Quoted 4 lines · Nicolas Cavallari

I'm not so sure now ... The fallback uses SYS_netns, instead of the kernel's __NR_setns, so i assume that there must be some C library support ... uclibc does define SYS_netns to be __NR_setns, so i think the problem is still valid if the toolchain does not define SYS_setns.

I was also confused by this, but it's actually util-linux itself that defines SYS_setns from __NR_setns.

From m4/ul.m4 in util-linux sources:

AC_DEFUN([UL_CHECK_SYSCALL], [
dnl This macro uses host_cpu.
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CACHE_CHECK([for syscall $1],

    [ul_cv_syscall_$1],
    [_UL_SYSCALL_CHECK_DECL([SYS_$1],
      [syscall=SYS_$1],
      [dnl Our libc failed use, so see if we can get the kernel
      dnl headers to play ball ...
      _UL_SYSCALL_CHECK_DECL([_NR_$1],
        [syscall=_NR_$1],
        [
          syscall=no
          if test "x$linux_os" = xyes; then
            case $host_cpu in
              _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
            esac
          fi
        ])
      ])
    ul_cv_syscall_$1=$syscall
    ])
  AM_CONDITIONAL([HAVE_]m4_toupper($1), [test "x$ul_cv_syscall_$1" != xno])
  case $ul_cv_syscall_$1 in #(
  no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
  SYS_*) ;;
  *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
        [Fallback syscall number for $1]) ;;

esac
])

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com