ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit f9dfa37f75b1c6f484850aa07070a555cfc46cf6
parent a770b91e62098da411ce2b301a28b9b99c2820c0
Author: sin <sin@2f30.org>
Date:   Mon, 12 Aug 2013 11:14:56 +0100

Add unshare(1)

No manpage yet.

Diffstat:
MMakefile | 3++-
Aunshare.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -26,7 +26,8 @@ SRC += \ reboot.c \ rmmod.c \ swapoff.c \ - swapon.c + swapon.c \ + unshare.c endif OBJ = $(SRC:.c=.o) $(LIB) diff --git a/unshare.c b/unshare.c @@ -0,0 +1,53 @@ +/* See LICENSE file for copyright and license details. */ +#include <sched.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s program [args]\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int flags = 0; + + ARGBEGIN { + case 'm': + flags |= CLONE_NEWNS; + break; + case 'u': + flags |= CLONE_NEWUTS; + break; + case 'i': + flags |= CLONE_NEWIPC; + break; + case 'n': + flags |= CLONE_NEWNET; + break; + case 'p': + flags |= CLONE_NEWPID; + break; + case 'U': + flags |= CLONE_NEWUSER; + break; + default: + usage(); + } ARGEND; + + if (argc < 1) + usage(); + + if (unshare(flags) < 0) + eprintf("unshare:"); + + if (execvp(argv[0], argv) < 0) + eprintf("execvp:"); + + return 0; +}