blob: 9b3d700444cd47749142029b0d5ad298b518e376 [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 *
Bernhard Reutner-Fischerd9cf7ac2006-04-12 18:39:58 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
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;
Eric Andersen2b69c401999-10-05 22:58:32 +000015int chroot_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000016{
Manuel Novoa III cad53642003-03-19 09:13:01 +000017 if (argc < 2) {
18 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +000019 }
Eric Andersencc8ed391999-10-05 16:24:54 +000020
Manuel Novoa III cad53642003-03-19 09:13:01 +000021 ++argv;
Denis Vlasenko394eebe2008-02-25 20:30:24 +000022 xchroot(*argv);
Rob Landleyd921b2e2006-08-03 15:41:12 +000023 xchdir("/");
Eric Andersen2b69c401999-10-05 22:58:32 +000024
Manuel Novoa III cad53642003-03-19 09:13:01 +000025 ++argv;
26 if (argc == 2) {
27 argv -= 2;
Denis Vlasenko99912ca2007-04-10 15:43:37 +000028 argv[0] = getenv("SHELL");
29 if (!argv[0]) {
30 argv[0] = (char *) DEFAULT_SHELL;
Manuel Novoa III cad53642003-03-19 09:13:01 +000031 }
32 argv[1] = (char *) "-i";
Erik Andersene49d5ec2000-02-08 19:58:47 +000033 }
Eric Andersen808d03e2000-06-02 17:56:45 +000034
Denis Vlasenko1d76f432007-02-06 01:20:12 +000035 BB_EXECVP(*argv, argv);
Denis Vlasenkof9d4fc32009-04-21 20:40:51 +000036 bb_perror_msg_and_die("can't execute '%s'", *argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000037}