]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: add --fork options for pid namespaces
authorMike Frysinger <vapier@gentoo.org>
Fri, 28 Jun 2013 00:04:58 +0000 (20:04 -0400)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Jul 2013 09:02:16 +0000 (11:02 +0200)
commit5088ec338fe5dcd7e9a2d8daf7e7fa7dd6f87c27
tree7dc914c23a62e7ffd07444db02474f1e58c6bb39
parentc9678832b15065f9a0147c308ed79d00f8d4237a
unshare: add --fork options for pid namespaces

The ability of unshare to launch a new pid namespace is a bit limited.
The first process in the namespace is expected to be the "init" for it.
When it's not, you get bad behavior.

For example, trying to launch a shell in a new pid namespace fails very
quickly:
$ sudo unshare -p dash
# uname -r
3.8.3
# uname -m
dash: 2: Cannot fork
# ls -ld /
dash: 3: Cannot fork
# echo $$
1324

For this to work smoothly, we need an init process to actively watch over
things.  But forcing people to re-use an existing init or write their own
mini init is a bit overkill.  So let's add a --fork option to unshare to
do this common bit of book keeping.  Now we can do:
$ sudo unshare -p --fork dash
# uname -r
3.8.3
# uname -m
x86_64
# ls -ld /
drwxr-xr-x 22 root root 4096 May  4 14:01 /
# echo $$
1

Thanks to Michael Kerrisk for his namespace articles on lwn.net

[kzak@redhat.com: - fix "forkif logic, remove --mount-proc]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/unshare.1
sys-utils/unshare.c