2023-10-04 17:12:38 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2023-10-11 21:07:22 +03:00
|
|
|
#include <string.h>
|
2023-10-11 19:46:57 +03:00
|
|
|
#include <errno.h>
|
2023-10-04 17:12:38 +03:00
|
|
|
|
2023-10-22 09:22:12 +03:00
|
|
|
int main(const int argc, char **argv) {
|
2023-10-22 09:26:38 +03:00
|
|
|
if (argc < 3 || !strcmp(argv[argc - 1], "--help")) {
|
|
|
|
printf("chroot [dir] [command arg arg2...]\n");
|
2023-10-12 16:17:40 +03:00
|
|
|
return 0;
|
2023-10-04 17:12:38 +03:00
|
|
|
}
|
|
|
|
|
2023-10-22 09:22:12 +03:00
|
|
|
if (chroot(argv[1]) < 0) {
|
2023-10-11 19:46:57 +03:00
|
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
2023-10-04 17:12:38 +03:00
|
|
|
|
2023-10-11 19:46:57 +03:00
|
|
|
chdir("/");
|
2023-10-22 09:40:31 +03:00
|
|
|
if (execvp(argv[2], argv + 2) < 0) {
|
2023-10-22 09:22:12 +03:00
|
|
|
fprintf(stderr, "chroot: %s\n", strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
2023-10-18 21:44:56 +03:00
|
|
|
|
|
|
|
return 0;
|
2023-10-04 17:12:38 +03:00
|
|
|
}
|