|
|
1.1 ! root 1: static char _version[]="chroot version 1.0"; ! 2: /* ! 3: * chroot - Change root ! 4: * ! 5: * usage: chroot dir program [args] ! 6: * ! 7: * Changes root to "dir" and runs "program". "program" should be a full ! 8: * pathname relative to the new root. "args" is an optional list of ! 9: * arguments for program. ! 10: */ ! 11: #include <stdio.h> ! 12: #include <errno.h> ! 13: ! 14: main(argc, argv) ! 15: int argc; ! 16: char *argv[]; ! 17: { ! 18: static char error_message[BUFSIZ]; ! 19: ! 20: if (argc < 3) { ! 21: fprintf(stderr, "usage: %s dir program [args]\n", argv[0]); ! 22: } else if (chroot(argv[1]) != 0) { ! 23: sprintf(error_message, "chroot failed: %s", argv[1]); ! 24: perror(error_message); ! 25: } else if (chdir("/") != 0) { ! 26: perror("chdir to / failed"); ! 27: } else if (execv(argv[2], &argv[2]) == -1) { ! 28: sprintf(error_message, "exec failed: %s", argv[2]); ! 29: perror(error_message); ! 30: } ! 31: exit(1); ! 32: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.