view toys/other/pivot_root.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 9e00446064fa
children da72fa267b7b
line wrap: on
line source

/* pivot_root.c - edit system mount tree
 *
 * Copyright 2012 Rob Landley <rob@landley.net>

USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_USR|TOYFLAG_BIN))

config PIVOT_ROOT
  bool "pivot_root"
  default y
  help
    usage: pivot_root OLD NEW

    Swap OLD and NEW filesystems (as if by simultaneous mount --move), and
    move all processes with chdir or chroot under OLD into NEW (including
    kernel threads) so OLD may be unmounted.

    The directory NEW must exist under OLD. This doesn't work on initramfs,
    which can't be moved (about the same way PID 1 can't be killed; see
    switch_root instead).
*/

#define FOR_pivot_root
#include "toys.h"

#include <linux/unistd.h>

void pivot_root_main(void)
{
  if (syscall(__NR_pivot_root, toys.optargs[0], toys.optargs[1]))
    perror_exit("'%s' -> '%s'", toys.optargs[0], toys.optargs[1]);
}