3
0

chroot.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini chroot implementation for busybox
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
  10. //usage:#define chroot_trivial_usage
  11. //usage: "NEWROOT [PROG ARGS]"
  12. //usage:#define chroot_full_usage "\n\n"
  13. //usage: "Run PROG with root directory set to NEWROOT"
  14. //usage:
  15. //usage:#define chroot_example_usage
  16. //usage: "$ ls -l /bin/ls\n"
  17. //usage: "lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox\n"
  18. //usage: "# mount /dev/hdc1 /mnt -t minix\n"
  19. //usage: "# chroot /mnt\n"
  20. //usage: "# ls -l /bin/ls\n"
  21. //usage: "-rwxr-xr-x 1 root root 40816 Feb 5 07:45 /bin/ls*\n"
  22. #include "libbb.h"
  23. int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  24. int chroot_main(int argc UNUSED_PARAM, char **argv)
  25. {
  26. ++argv;
  27. if (!*argv)
  28. bb_show_usage();
  29. xchroot(*argv);
  30. ++argv;
  31. if (!*argv) { /* no 2nd param (PROG), use shell */
  32. argv -= 2;
  33. argv[0] = (char *) get_shell_name();
  34. argv[1] = (char *) "-i"; /* GNU coreutils 8.4 compat */
  35. /*argv[2] = NULL; - already is */
  36. }
  37. BB_EXECVP_or_die(argv);
  38. }