]> git.ipfire.org Git - thirdparty/util-linux.git/commit
nsenter: use pidfd to enter target namespaces
authorKarel Zak <kzak@redhat.com>
Fri, 18 Oct 2024 10:16:04 +0000 (12:16 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 21 Oct 2024 12:36:50 +0000 (14:36 +0200)
commitf18be0ca5aa764404aa626c84cff315256c9ee73
tree18a8c0050de66150bc3e289c1fcc52556be30a62
parented0da317e078bc2c86ccf4d882b3867edd726253
nsenter: use pidfd to enter target namespaces

The typical use case is to enter namespaces of the task (--target
<pid>). The original nsenter opens /proc/<pid>/ns/* files and uses the
file descriptors to enter the namespaces by setns(). The recent kernel
allows using the pid file descriptor instead of the files in /proc,
making it possible to enter multiple namespaces with one setns call.
This solution reduces the number of syscalls (open+setns for each
namespace), removes the dependence on /proc, and allows entering
nested namespaces.

This commit should be backwardly compatible, meaning it can be used on
systems without pidfd_open(). Explicitly specified namespaces by
filenames are still supported, and user namespaces are still entered
first/last according to permissions privileging/deprivileging.

Addresses: https://github.com/util-linux/util-linux/pull/301
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/nsenter.c