ubase

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

unshare.c (772B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sched.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 #include <unistd.h>
      7 
      8 #include "util.h"
      9 
     10 static void
     11 usage(void)
     12 {
     13 	eprintf("usage: %s [-muinpU] cmd [args...]\n", argv0);
     14 }
     15 
     16 int
     17 main(int argc, char *argv[])
     18 {
     19 	int flags = 0;
     20 
     21 	ARGBEGIN {
     22 	case 'm':
     23 		flags |= CLONE_NEWNS;
     24 		break;
     25 	case 'u':
     26 		flags |= CLONE_NEWUTS;
     27 		break;
     28 	case 'i':
     29 		flags |= CLONE_NEWIPC;
     30 		break;
     31 	case 'n':
     32 		flags |= CLONE_NEWNET;
     33 		break;
     34 	case 'p':
     35 		flags |= CLONE_NEWPID;
     36 		break;
     37 	case 'U':
     38 		flags |= CLONE_NEWUSER;
     39 		break;
     40 	default:
     41 		usage();
     42 	} ARGEND;
     43 
     44 	if (argc < 1)
     45 		usage();
     46 
     47 	if (unshare(flags) < 0)
     48 		eprintf("unshare:");
     49 
     50 	if (execvp(argv[0], argv) < 0)
     51 		eprintf("execvp:");
     52 
     53 	return 0;
     54 }