Utilities: Use Core::Environment instead of Core::System::*env()

This commit is contained in:
Sam Atkins 2024-02-07 16:06:58 +00:00 committed by Sam Atkins
parent b9dc2d7ebf
commit 7109f3706e
Notes: sideshowbarker 2024-07-17 06:35:16 +09:00
4 changed files with 11 additions and 8 deletions

View file

@ -8,6 +8,7 @@
#include <AK/ByteString.h>
#include <AK/Format.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
@ -27,7 +28,7 @@ static void spawn_command(Span<StringView> command, ByteBuffer const& data, char
MUST(Core::System::dup2(pipefd[0], 0));
MUST(Core::System::close(pipefd[0]));
MUST(Core::System::close(pipefd[1]));
MUST(Core::System::setenv("CLIPBOARD_STATE"sv, { state, strlen(state) }, true));
MUST(Core::Environment::set("CLIPBOARD_STATE"sv, { state, strlen(state) }, Core::Environment::Overwrite::Yes));
MUST(Core::System::exec(command[0], command, Core::System::SearchInPath::Yes));
perror("exec");
exit(1);

View file

@ -6,6 +6,7 @@
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/MappedFile.h>
#include <LibCore/System.h>
#include <LibELF/Image.h>
@ -33,8 +34,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (add_promises_for_dynamic_linker && TRY(is_dynamically_linked_executable(command[0]))) {
auto constexpr loader_promises = "stdio rpath prot_exec"sv;
MUST(Core::System::setenv("_LOADER_PLEDGE_PROMISES"sv, loader_promises, true));
MUST(Core::System::setenv("_LOADER_MAIN_PROGRAM_PLEDGE_PROMISES"sv, promises, true));
MUST(Core::Environment::set("_LOADER_PLEDGE_PROMISES"sv, loader_promises, Core::Environment::Overwrite::Yes));
MUST(Core::Environment::set("_LOADER_MAIN_PROGRAM_PLEDGE_PROMISES"sv, promises, Core::Environment::Overwrite::Yes));
promises = ByteString::formatted("{} {}", promises, loader_promises);
}

View file

@ -7,6 +7,7 @@
#include <AK/LexicalPath.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/Environment.h>
#include <LibCore/System.h>
#include <LibCoredump/Backtrace.h>
#include <LibFileSystem/FileSystem.h>
@ -360,15 +361,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
test_glob = ByteString::formatted("*{}*", test_glob);
if (getenv("DISABLE_DBG_OUTPUT")) {
if (Core::Environment::has("DISABLE_DBG_OUTPUT"sv))
AK::set_debug_enabled(false);
}
// Make UBSAN deadly for all tests we run by default.
TRY(Core::System::setenv("UBSAN_OPTIONS"sv, "halt_on_error=1"sv, true));
TRY(Core::Environment::set("UBSAN_OPTIONS"sv, "halt_on_error=1"sv, Core::Environment::Overwrite::Yes));
if (!run_benchmarks)
TRY(Core::System::setenv("TESTS_ONLY"sv, "1"sv, true));
TRY(Core::Environment::set("TESTS_ONLY"sv, "1"sv, Core::Environment::Overwrite::Yes));
ByteString test_root;

View file

@ -7,6 +7,7 @@
#include <LibCore/Account.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/GetPassword.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
@ -60,7 +61,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio exec"));
TRY(Core::System::setenv("HOME"sv, account.home_directory(), true));
TRY(Core::Environment::set("HOME"sv, account.home_directory(), Core::Environment::Overwrite::Yes));
if (command.is_null()) {
TRY(Core::System::exec(account.shell(), Array<StringView, 1> { account.shell().view() }, Core::System::SearchInPath::No));