ubase/unshare.c

55 lines
772 B
C
Raw Normal View History

2013-08-12 10:14:56 +00:00
/* See LICENSE file for copyright and license details. */
2014-06-30 18:03:41 +00:00
#include <sched.h>
2013-08-12 10:14:56 +00:00
#include <stdio.h>
2013-10-07 18:11:40 +00:00
#include <stdlib.h>
2013-08-12 10:14:56 +00:00
#include <string.h>
2014-06-30 18:03:41 +00:00
#include <unistd.h>
2013-08-12 10:14:56 +00:00
#include "util.h"
static void
usage(void)
{
2014-02-24 13:51:03 +00:00
eprintf("usage: %s [-muinpU] cmd [args...]\n", argv0);
2013-08-12 10:14:56 +00:00
}
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:");
2014-10-02 22:45:25 +00:00
return 0;
2013-08-12 10:14:56 +00:00
}