summaryrefslogtreecommitdiff
path: root/Userland/chroot.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-10 23:23:20 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-10 23:23:20 +0100
commit3f9e4cd24e89c13018947fc967d1801b17c0ec3f (patch)
treee7e18c3768a0aefc6ac717e26a4394e459ac1c88 /Userland/chroot.cpp
parentddd0b192819b3d782682a47e463dc30ee29c739e (diff)
downloadserenity-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.cpp27
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;
+}