view toys/chroot.c @ 239:4f1ca01db000

Fluff out hello.c to supply more example code as a skeleton for new commands, and update a chunk of code.html (much more to do there).
author Rob Landley <>
date Sun, 20 Jan 2008 19:00:16 -0600
parents 163498bf547b
children 064fc1b8b7b1
line wrap: on
line source

/* vi: set sw=4 ts=4:
 * chroot.c - Run command in new root directory.
 * Copyright 2007 Rob Landley <>
 * Not in SUSv3.


config CHROOT
	bool "chroot"
	default y
	  usage: chroot NEWPATH [commandline...]

	  Run command within a new root directory.  If no command, run /bin/sh.

#include "toys.h"

void chroot_main(void)
	char *binsh[] = {"/bin/sh", "-i", 0};
	if (chdir(*toys.optargs) || chroot("."))
		perror_exit("%s", *toys.optargs);
	xexec(toys.optargs[1] ? toys.optargs+1 : binsh);