From b6c4a2dbf12792df4b5523f38247c37f2d0d910d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 7 Jul 2023 23:12:19 +0300 Subject: [PATCH] Kernel: Edit lock scopes and make string copy able to fail --- kernel/kernel/Process.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 7b1033b942..ea79915104 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -577,8 +577,8 @@ namespace Kernel BAN::String absolute_source, absolute_target; { LockGuard _(m_lock); - absolute_source = TRY(absolute_path_of(source)); - absolute_target = TRY(absolute_path_of(target)); + TRY(absolute_source.append(TRY(absolute_path_of(source)))); + TRY(absolute_target.append(TRY(absolute_path_of(target)))); } TRY(VirtualFileSystem::get().mount(m_credentials, absolute_source, absolute_target)); return {}; @@ -593,6 +593,7 @@ namespace Kernel BAN::ErrorOr Process::sys_stat(BAN::StringView path, struct stat* out, int flags) { + LockGuard _(m_lock); int fd = TRY(sys_open(path, flags)); auto ret = sys_fstat(fd, out); MUST(sys_close(fd)); @@ -935,18 +936,14 @@ namespace Kernel BAN::ErrorOr Process::absolute_path_of(BAN::StringView path) const { + ASSERT(m_lock.is_locked()); + if (path.empty() || path == "."sv) - { - LockGuard _(m_lock); return m_working_directory; - } BAN::String absolute_path; if (path.front() != '/') - { - LockGuard _(m_lock); TRY(absolute_path.append(m_working_directory)); - } if (!absolute_path.empty() && absolute_path.back() != '/') TRY(absolute_path.push_back('/'));