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

Kernel: Expose a process's filesystem root as a /proc/PID/root symlink

In order to preserve the absolute path of the process root, we save the
custody used by chroot() before stripping it to become the new "/".
There's probably a better way to do this.
This commit is contained in:
Andreas Kling 2020-01-10 23:48:44 +01:00
parent 3f9e4cd24e
commit 29b3d95004
3 changed files with 21 additions and 0 deletions

View file

@ -4146,6 +4146,7 @@ int Process::sys$chroot(const char* user_path, size_t path_length)
auto directory_or_error = VFS::the().open_directory(path.value(), current_directory());
if (directory_or_error.is_error())
return directory_or_error.error();
m_root_directory_for_procfs = directory_or_error.value();
set_root_directory(Custody::create(nullptr, "", directory_or_error.value()->inode()));
return 0;
}
@ -4157,6 +4158,13 @@ Custody& Process::root_directory()
return *m_root_directory;
}
Custody& Process::root_directory_for_procfs()
{
if (!m_root_directory_for_procfs)
m_root_directory_for_procfs = root_directory();
return *m_root_directory_for_procfs;
}
void Process::set_root_directory(const Custody& root)
{
m_root_directory = root;