aboutsummaryrefslogtreecommitdiff
path: root/coreutils/chroot.c
blob: ca0bfcf3fbc6c58a3506b5c2f36b8049f1273b83 (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
26
27
28
29
30
31
32
#include "internal.h"
#include <stdio.h>
#include <unistd.h>


const char chroot_usage[] = "chroot directory [command]\n"
  "Run a command with special root directory.\n";

extern int
chroot_main (struct FileInfo *i, int argc, char **argv)
{
  char *prog;

  if (chroot (argv[1]))
    {
      name_and_error ("cannot chroot to that directory");
      return 1;
    }
  if (argc > 2)
    {
      execvp (argv[2], argv + 2);
    }
  else
    {
      prog = getenv ("SHELL");
      if (!prog)
	prog = "/bin/sh";
      execlp (prog, prog, NULL);
    }
  name_and_error ("cannot exec");
  return 1;
}