1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

chroot: Add a little chroot program

This program changes the current filesystem root and spawns a shell.
This commit is contained in:
Andreas Kling 2020-01-10 23:23:20 +01:00
parent ddd0b19281
commit 3f9e4cd24e
3 changed files with 81 additions and 0 deletions

27
Userland/chroot.cpp Normal file
View file

@ -0,0 +1,27 @@
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: chroot <path>\n");
return 0;
}
if (chroot(argv[1]) < 0) {
perror("chroot");
return 1;
}
if (chdir("/") < 0) {
perror("chdir(/)");
return 1;
}
if (execl("/bin/Shell", "Shell", nullptr) < 0) {
perror("execl");
return 1;
}
return 0;
}