view toys/other/unshare.c @ 979:53a9bcb938f0

Move renice from pending to posix, default y, fix link to standard.
author Rob Landley <rob@landley.net>
date Wed, 31 Jul 2013 16:36:57 -0500
parents 144d5ba7d410
children 0d0c01ac5c63
line wrap: on
line source

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

USE_UNSHARE(NEWTOY(unshare, "<1^nium", 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:

    -m	Mount/unmount tree
    -u	Host and domain names
    -i	SysV IPC (message queues, semaphores, shared memory)
    -n	Network address, sockets, routing, iptables
*/

#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, 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);
}