diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-06 12:24:36 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 13:06:05 +0200 |
commit | cda2b9e71cca1793d47427fb5b43b10dd0f3fbb6 (patch) | |
tree | 5a8b3aa7c7f2ea630fcb6472a0c3582b8daa7cb9 /Kernel/Syscalls | |
parent | f173f73f10795722b39793af11fda9c730a5ca9f (diff) | |
download | serenity-cda2b9e71cca1793d47427fb5b43b10dd0f3fbb6.zip |
Kernel: Improvements to Custody absolute path serialization
- Renamed try_create_absolute_path() => try_serialize_absolute_path()
- Use KResultOr and TRY() to propagate errors
- Don't call this when it's only for debug logging
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r-- | Kernel/Syscalls/chdir.cpp | 10 | ||||
-rw-r--r-- | Kernel/Syscalls/realpath.cpp | 5 | ||||
-rw-r--r-- | Kernel/Syscalls/unveil.cpp | 8 |
3 files changed, 6 insertions, 17 deletions
diff --git a/Kernel/Syscalls/chdir.cpp b/Kernel/Syscalls/chdir.cpp index 7b200e9f25..327da07a36 100644 --- a/Kernel/Syscalls/chdir.cpp +++ b/Kernel/Syscalls/chdir.cpp @@ -40,14 +40,10 @@ KResultOr<FlatPtr> Process::sys$getcwd(Userspace<char*> buffer, size_t size) if (size > NumericLimits<ssize_t>::max()) return EINVAL; - auto maybe_path = current_directory().try_create_absolute_path(); - if (!maybe_path) - return ENOMEM; - auto& path = *maybe_path; - - size_t ideal_size = path.length() + 1; + auto path = TRY(current_directory().try_serialize_absolute_path()); + size_t ideal_size = path->length() + 1; auto size_to_copy = min(ideal_size, size); - TRY(copy_to_user(buffer, path.characters(), size_to_copy)); + TRY(copy_to_user(buffer, path->characters(), size_to_copy)); // Note: we return the whole size here, not the copied size. return ideal_size; } diff --git a/Kernel/Syscalls/realpath.cpp b/Kernel/Syscalls/realpath.cpp index bbb44e026c..cf219bc1a0 100644 --- a/Kernel/Syscalls/realpath.cpp +++ b/Kernel/Syscalls/realpath.cpp @@ -19,10 +19,7 @@ KResultOr<FlatPtr> Process::sys$realpath(Userspace<const Syscall::SC_realpath_pa auto path = TRY(get_syscall_path_argument(params.path)); auto custody = TRY(VirtualFileSystem::the().resolve_path(path->view(), current_directory())); - - auto absolute_path = custody->try_create_absolute_path(); - if (!absolute_path) - return ENOMEM; + auto absolute_path = TRY(custody->try_serialize_absolute_path()); size_t ideal_size = absolute_path->length() + 1; auto size_to_copy = min(ideal_size, params.buffer.size); diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp index 56d5046f4c..ebdc915649 100644 --- a/Kernel/Syscalls/unveil.cpp +++ b/Kernel/Syscalls/unveil.cpp @@ -83,13 +83,9 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params OwnPtr<KString> new_unveiled_path; auto custody_or_error = VirtualFileSystem::the().resolve_path_without_veil(path->view(), VirtualFileSystem::the().root_custody(), &parent_custody); if (!custody_or_error.is_error()) { - new_unveiled_path = custody_or_error.value()->try_create_absolute_path(); - if (!new_unveiled_path) - return ENOMEM; + new_unveiled_path = TRY(custody_or_error.value()->try_serialize_absolute_path()); } else if (custody_or_error.error() == ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) { - auto parent_custody_path = parent_custody->try_create_absolute_path(); - if (!parent_custody_path) - return ENOMEM; + auto parent_custody_path = TRY(parent_custody->try_serialize_absolute_path()); new_unveiled_path = KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path->view())); if (!new_unveiled_path) return ENOMEM; |