blob: 5ac2e890e1e2c1e50f12eee053ec73fd6f68fb5f [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen2b69c401999-10-05 22:58:32 +00002/*
3 * Mini chroot implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen2b69c401999-10-05 22:58:32 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen2b69c401999-10-05 22:58:32 +00008 */
9
Manuel Novoa III cad53642003-03-19 09:13:01 +000010/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000012#include "libbb.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000013
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000014int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010015int chroot_main(int argc UNUSED_PARAM, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000016{
Manuel Novoa III cad53642003-03-19 09:13:01 +000017 ++argv;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010018 if (!*argv)
19 bb_show_usage();
Denis Vlasenko394eebe2008-02-25 20:30:24 +000020 xchroot(*argv);
Rob Landleyd921b2e2006-08-03 15:41:12 +000021 xchdir("/");
Eric Andersen2b69c401999-10-05 22:58:32 +000022
Manuel Novoa III cad53642003-03-19 09:13:01 +000023 ++argv;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010024 if (!*argv) { /* no 2nd param (PROG), use shell */
Manuel Novoa III cad53642003-03-19 09:13:01 +000025 argv -= 2;
Denys Vlasenko681efe22011-03-08 21:00:36 +010026 argv[0] = (char *) get_shell_name();
27 argv[1] = (char *) "-i"; /* GNU coreutils 8.4 compat */
28 /*argv[2] = NULL; - already is */
Erik Andersene49d5ec2000-02-08 19:58:47 +000029 }
Eric Andersen808d03e2000-06-02 17:56:45 +000030
Pascal Bellard21e8e8d2010-07-04 00:57:03 +020031 BB_EXECVP_or_die(argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000032}