mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Don't do path resolution in sys$chdir() while holding spinlock
Path resolution may do blocking I/O so we must not do it while holding a spinlock. There are tons of problems like this throughout the kernel and we need to find and fix all of them.
This commit is contained in:
parent
51bc87d15a
commit
ae8558dd5c
1 changed files with 8 additions and 3 deletions
|
@ -15,10 +15,15 @@ ErrorOr<FlatPtr> Process::sys$chdir(Userspace<char const*> user_path, size_t pat
|
|||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
TRY(require_promise(Pledge::rpath));
|
||||
auto path = TRY(get_syscall_path_argument(user_path, path_length));
|
||||
return m_current_directory.with([&](auto& current_directory) -> ErrorOr<FlatPtr> {
|
||||
current_directory = TRY(VirtualFileSystem::the().open_directory(path->view(), *current_directory));
|
||||
return 0;
|
||||
auto current_directory = m_current_directory.with([](auto& current_directory) -> NonnullRefPtr<Custody> {
|
||||
return *current_directory;
|
||||
});
|
||||
RefPtr<Custody> new_directory = TRY(VirtualFileSystem::the().open_directory(path->view(), *current_directory));
|
||||
m_current_directory.with([&](auto& current_directory) {
|
||||
// NOTE: We use swap() here to avoid manipulating the ref counts while holding the lock.
|
||||
swap(current_directory, new_directory);
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$fchdir(int fd)
|
||||
|
|
Loading…
Add table
Reference in a new issue