diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-08-20 18:31:03 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-23 19:00:04 +0100 |
commit | 5f99934dce1e00f5856bd40dca9d5e86e71d625e (patch) | |
tree | aaec591e2fd977714fa200a184c8b5ec701c73e9 /Userland/Utilities | |
parent | 39a3775f4870fb16b49fec24aa5fd506b17a0ea9 (diff) | |
download | serenity-5f99934dce1e00f5856bd40dca9d5e86e71d625e.zip |
Userland: Consolidate most PATH resolving into a single implementation
We previously had at least three different implementations for resolving
executables in the PATH, all of which had slightly different
characteristics.
Merge those into a single implementation to keep the behaviour
consistent, and maybe to make that implementation more configurable in
the future.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/pledge.cpp | 11 | ||||
-rw-r--r-- | Userland/Utilities/which.cpp | 8 |
2 files changed, 10 insertions, 9 deletions
diff --git a/Userland/Utilities/pledge.cpp b/Userland/Utilities/pledge.cpp index 5d4b5e4653..90f41b357b 100644 --- a/Userland/Utilities/pledge.cpp +++ b/Userland/Utilities/pledge.cpp @@ -5,6 +5,7 @@ */ #include <LibCore/ArgsParser.h> +#include <LibCore/File.h> #include <LibCore/MappedFile.h> #include <LibCore/System.h> #include <LibELF/Image.h> @@ -12,12 +13,12 @@ static ErrorOr<bool> is_dynamically_linked_executable(StringView filename) { - String exec_filename = filename; - if (!filename.contains('/')) { - exec_filename = TRY(Core::System::find_file_in_path(filename)); - } + auto maybe_executable = Core::File::resolve_executable_from_environment(filename); + + if (!maybe_executable.has_value()) + return ENOENT; - auto file = TRY(Core::MappedFile::map(exec_filename)); + auto file = TRY(Core::MappedFile::map(maybe_executable.release_value())); ELF::Image elf_image(file->bytes()); return elf_image.is_dynamic(); } diff --git a/Userland/Utilities/which.cpp b/Userland/Utilities/which.cpp index aace9ea20b..96cceb0958 100644 --- a/Userland/Utilities/which.cpp +++ b/Userland/Utilities/which.cpp @@ -5,7 +5,7 @@ */ #include <LibCore/ArgsParser.h> -#include <LibCore/DirIterator.h> +#include <LibCore/File.h> #include <LibCore/System.h> #include <stdio.h> #include <unistd.h> @@ -20,12 +20,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) args_parser.add_positional_argument(filename, "Name of executable", "executable"); args_parser.parse(arguments); - auto fullpath = Core::find_executable_in_path(filename); - if (fullpath.is_empty()) { + auto fullpath = Core::File::resolve_executable_from_environment({ filename, strlen(filename) }); + if (!fullpath.has_value()) { warnln("no '{}' in path", filename); return 1; } - outln("{}", fullpath); + outln("{}", fullpath.release_value()); return 0; } |