From 7109f3706e778b6bea8031188dcd5316b6280a3f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 7 Feb 2024 16:06:58 +0000 Subject: [PATCH] Utilities: Use Core::Environment instead of Core::System::*env() --- Userland/Utilities/paste.cpp | 3 ++- Userland/Utilities/pledge.cpp | 5 +++-- Userland/Utilities/run-tests.cpp | 8 ++++---- Userland/Utilities/su.cpp | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Userland/Utilities/paste.cpp b/Userland/Utilities/paste.cpp index 58eef8c282b..ba87b96e914 100644 --- a/Userland/Utilities/paste.cpp +++ b/Userland/Utilities/paste.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,7 @@ static void spawn_command(Span 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); diff --git a/Userland/Utilities/pledge.cpp b/Userland/Utilities/pledge.cpp index 6cb5e2270e2..e0742d7546d 100644 --- a/Userland/Utilities/pledge.cpp +++ b/Userland/Utilities/pledge.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -33,8 +34,8 @@ ErrorOr 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); } diff --git a/Userland/Utilities/run-tests.cpp b/Userland/Utilities/run-tests.cpp index bdd5da182ee..6c112deccf1 100644 --- a/Userland/Utilities/run-tests.cpp +++ b/Userland/Utilities/run-tests.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -360,15 +361,14 @@ ErrorOr 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; diff --git a/Userland/Utilities/su.cpp b/Userland/Utilities/su.cpp index c26bba76500..d1511528288 100644 --- a/Userland/Utilities/su.cpp +++ b/Userland/Utilities/su.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -60,7 +61,7 @@ ErrorOr 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 { account.shell().view() }, Core::System::SearchInPath::No));