aboutsummaryrefslogtreecommitdiffstats
path: root/sys-utils/chroot.c
blob: 7ddbe791fa5ae605eae7bc0c1c6a7c73a9a1be87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * chroot.c -- change root directory and execute a command there
 * Rick Sladkey <jrs@world.std.com>
 * In the public domain.
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	if (argc < 3) {
		fprintf(stderr, "usage: %s directory program [arg ...]\n",
			argv[0]);
		exit(1);
	}
	if (chroot(argv[1]) < 0) {
		perror("chroot");
		exit(1);
	}
	execvp(argv[2], argv + 2);
	perror("execvp");
	exit(1);
}