mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 05:55:13 +00:00
chroot: Add a little chroot program
This program changes the current filesystem root and spawns a shell.
This commit is contained in:
parent
ddd0b19281
commit
3f9e4cd24e
Notes:
sideshowbarker
2024-07-19 10:12:45 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3f9e4cd24e8
3 changed files with 81 additions and 0 deletions
26
Base/usr/share/man/man2/chroot.md
Normal file
26
Base/usr/share/man/man2/chroot.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
## Name
|
||||||
|
|
||||||
|
chroot - change filesystem root
|
||||||
|
|
||||||
|
## Synopsis
|
||||||
|
|
||||||
|
```**c++
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int chroot(const char* path);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
`chroot()` changes the filesystem root of the current process to a new directory specified by `path`.
|
||||||
|
|
||||||
|
## Errors
|
||||||
|
|
||||||
|
* `EPERM`: The current process does not have superuser privileges.
|
||||||
|
* `EFAULT`: `path` is not in readable memory.
|
||||||
|
|
||||||
|
All of the usual path resolution errors may also occur.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
* [`chroot`(8)](../man8/chroot.md)
|
28
Base/usr/share/man/man8/chroot.md
Normal file
28
Base/usr/share/man/man8/chroot.md
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
## Name
|
||||||
|
|
||||||
|
chroot - run a shell with a different filesystem root
|
||||||
|
|
||||||
|
## Synopsis
|
||||||
|
|
||||||
|
```**sh
|
||||||
|
# chroot
|
||||||
|
```
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This program uses the [`chroot`(2)](../man2/chroot.md) syscall to switch into a
|
||||||
|
different filesystem root and spawn a shell inside it.
|
||||||
|
|
||||||
|
It will not work unless there is a `/bin/Shell` available inside the new root.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# chroot /var/chroot
|
||||||
|
# pwd
|
||||||
|
/
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
* [`chroot`(2)](../man2/chroot.md)
|
27
Userland/chroot.cpp
Normal file
27
Userland/chroot.cpp
Normal 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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue