micro-utils/coreutils/chroot.c

22 lines
389 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(const int argc, const char **argv) {
if (argc <= 2) {
printf("chroot [dir] [\"command arg\"]\n");
return 0;
}
if (chroot(argv[1]) == -1) {
fprintf(stderr, "chroot: %s\n", strerror(errno));
return 1;
}
chdir("/");
for (int i = 2; i < argc; i++)
system(argv[i]);
}