home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / sys-utils / chroot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  455 b   |  26 lines

  1. /*
  2.  * chroot.c -- change root directory and execute a command there
  3.  * Rick Sladkey <jrs@world.std.com>
  4.  * In the public domain.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     if (argc < 3) {
  14.         fprintf(stderr, "usage: %s directory program [arg ...]\n",
  15.             argv[0]);
  16.         exit(1);
  17.     }
  18.     if (chroot(argv[1]) < 0) {
  19.         perror("chroot");
  20.         exit(1);
  21.     }
  22.     execvp(argv[2], argv + 2);
  23.     perror("execvp");
  24.     exit(1);
  25. }
  26.