diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-10 23:23:20 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-10 23:23:20 +0100 |
commit | 3f9e4cd24e89c13018947fc967d1801b17c0ec3f (patch) | |
tree | e7e18c3768a0aefc6ac717e26a4394e459ac1c88 /Userland/chroot.cpp | |
parent | ddd0b192819b3d782682a47e463dc30ee29c739e (diff) | |
download | serenity-3f9e4cd24e89c13018947fc967d1801b17c0ec3f.zip |
chroot: Add a little chroot program
This program changes the current filesystem root and spawns a shell.
Diffstat (limited to 'Userland/chroot.cpp')
-rw-r--r-- | Userland/chroot.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Userland/chroot.cpp b/Userland/chroot.cpp new file mode 100644 index 0000000000..890d18ac02 --- /dev/null +++ b/Userland/chroot.cpp @@ -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; +} |