mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +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:
parent
3f9e4cd24e
commit
29b3d95004
Notes:
sideshowbarker
2024-07-19 10:12:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/29b3d950044
3 changed files with 21 additions and 0 deletions
|
@ -80,6 +80,7 @@ enum ProcFileType {
|
|||
FI_PID_fds,
|
||||
FI_PID_exe, // symlink
|
||||
FI_PID_cwd, // symlink
|
||||
FI_PID_root, // symlink
|
||||
FI_PID_fd, // directory
|
||||
__FI_PID_End,
|
||||
|
||||
|
@ -571,6 +572,14 @@ Optional<KBuffer> procfs$pid_cwd(InodeIdentifier identifier)
|
|||
return handle->process().current_directory().absolute_path().to_byte_buffer();
|
||||
}
|
||||
|
||||
Optional<KBuffer> procfs$pid_root(InodeIdentifier identifier)
|
||||
{
|
||||
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
|
||||
if (!handle)
|
||||
return {};
|
||||
return handle->process().root_directory_for_procfs().absolute_path().to_byte_buffer();
|
||||
}
|
||||
|
||||
Optional<KBuffer> procfs$self(InodeIdentifier)
|
||||
{
|
||||
char buffer[16];
|
||||
|
@ -1030,6 +1039,7 @@ InodeMetadata ProcFSInode::metadata() const
|
|||
break;
|
||||
case FI_PID_cwd:
|
||||
case FI_PID_exe:
|
||||
case FI_PID_root:
|
||||
metadata.mode = 0120400;
|
||||
break;
|
||||
case FI_Root:
|
||||
|
@ -1408,6 +1418,7 @@ ProcFS::ProcFS()
|
|||
m_entries[FI_PID_fds] = { "fds", FI_PID_fds, false, procfs$pid_fds };
|
||||
m_entries[FI_PID_exe] = { "exe", FI_PID_exe, false, procfs$pid_exe };
|
||||
m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, false, procfs$pid_cwd };
|
||||
m_entries[FI_PID_root] = { "root", FI_PID_root, false, procfs$pid_root };
|
||||
m_entries[FI_PID_fd] = { "fd", FI_PID_fd, false };
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -311,6 +311,7 @@ public:
|
|||
u32 priority_boost() const { return m_priority_boost; }
|
||||
|
||||
Custody& root_directory();
|
||||
Custody& root_directory_for_procfs();
|
||||
void set_root_directory(const Custody&);
|
||||
|
||||
private:
|
||||
|
@ -374,6 +375,7 @@ private:
|
|||
RefPtr<Custody> m_executable;
|
||||
RefPtr<Custody> m_cwd;
|
||||
RefPtr<Custody> m_root_directory;
|
||||
RefPtr<Custody> m_root_directory_for_procfs;
|
||||
|
||||
RefPtr<TTY> m_tty;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue