view toys/other/unshare.c @ 1183:0752b2d58909 draft

Rename xmsprintf() to just xmprintf(). Partly because there's no supplied target string ala sprintf, and partly because I can never remember what order the m and s go in.
author Rob Landley <rob@landley.net>
date Thu, 16 Jan 2014 09:26:50 -0600
parents 0d0c01ac5c63
children 33b3b5f9e6c6
line wrap: on
line source

/* unshare.c - run command in new context
 *
 * Copyright 2011 Rob Landley <rob@landley.net>

USE_UNSHARE(NEWTOY(unshare, "<1^niumpU", TOYFLAG_USR|TOYFLAG_BIN))

config UNSHARE
  bool "unshare"
  default y
  depends on TOYBOX_CONTAINER
  help
    usage: unshare [-muin] COMMAND...

    Create new namespace(s) for this process and its children, so some
    attribute is not shared with the parent process.  This is part of
    Linux Containers.  Each process can have its own:

    -i	SysV IPC (message queues, semaphores, shared memory)
    -m	Mount/unmount tree
    -n	Network address, sockets, routing, iptables
    -p	Process IDs and init
    -u	Host and domain names
    -U  UIDs, GIDs, capabilities
*/

#include "toys.h"
#include <linux/sched.h>
extern int unshare (int __flags);

void unshare_main(void)
{
  unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,
                    CLONE_NEWPID, CLONE_NEWUSER, 0};
  unsigned f=0;
  int i;

  for (i=0; flags[i]; i++) if (toys.optflags & (1<<i)) f |= flags[i];

  if(unshare(f)) perror_exit("failed");

  xexec_optargs(0);
}