26 lines
487 B
C
26 lines
487 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;
|
|
}
|
|
|
|
chdir("/");
|
|
if (execvp(argv[2], argv + 2) < 0) {
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|