34 lines
605 B
C
34 lines
605 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
int opt;
|
|
while ((opt = getopt(argc, argv, "")) != -1 || argc == 1) {
|
|
puts("chroot [dir] [command] [arg arg2...]");
|
|
return 0;
|
|
}
|
|
|
|
argv += optind;
|
|
argc -= optind;
|
|
|
|
if (chroot(argv[1]) < 0) {
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
if (chdir("/") < 0) {
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
if (execvp(argv[0], argv) < 0) {
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|