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
|
|
|
|
|
|
|
int main(const int argc, const char **argv) {
|
|
|
|
if (argc <= 2) {
|
2023-10-12 16:17:40 +03:00
|
|
|
printf("chroot [dir] [\"command arg\"]\n");
|
|
|
|
return 0;
|
2023-10-04 17:12:38 +03:00
|
|
|
}
|
|
|
|
|
2023-10-11 19:46:57 +03:00
|
|
|
if (chroot(argv[1]) == -1) {
|
|
|
|
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-04 17:12:38 +03:00
|
|
|
for (int i = 2; i < argc; i++)
|
|
|
|
system(argv[i]);
|
|
|
|
}
|