30 lines
567 B
C
30 lines
567 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
#include <errno.h>
|
||
|
|
||
|
int main(const int argc, char **argv) {
|
||
|
if (argc < 3 || !strcmp(argv[argc - 1], "--help")) {
|
||
|
printf("chroot [dir] [command] [arg arg2...]\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
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[2], argv + 2) < 0) {
|
||
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|