From c2bc07ef7c9c3f631cf47f5aec500a66b8e43d7d Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 30 Jan 2024 18:30:22 +0000 Subject: [PATCH] LibCore: Use Core::Environment::raw_environ() instead of environment() --- Userland/Libraries/LibCore/Command.cpp | 3 ++- Userland/Libraries/LibCore/Process.cpp | 7 ++++--- Userland/Libraries/LibCore/System.cpp | 12 +----------- Userland/Libraries/LibCore/System.h | 4 +--- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Userland/Libraries/LibCore/Command.cpp b/Userland/Libraries/LibCore/Command.cpp index 86505babd5..5c24d7c2b1 100644 --- a/Userland/Libraries/LibCore/Command.cpp +++ b/Userland/Libraries/LibCore/Command.cpp @@ -9,6 +9,7 @@ #include "Command.h" #include #include +#include #include #include #include @@ -30,7 +31,7 @@ ErrorOr> Command::create(StringView command, char const* const a posix_spawn_file_actions_adddup2(&file_actions, stdout_fds[1], STDOUT_FILENO); posix_spawn_file_actions_adddup2(&file_actions, stderr_fds[1], STDERR_FILENO); - auto pid = TRY(Core::System::posix_spawnp(command, &file_actions, nullptr, const_cast(arguments), System::environment())); + auto pid = TRY(Core::System::posix_spawnp(command, &file_actions, nullptr, const_cast(arguments), Core::Environment::raw_environ())); posix_spawn_file_actions_destroy(&file_actions); ArmedScopeGuard runner_kill { [&pid] { kill(pid, SIGKILL); } }; diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 9ad3b50231..915af3c213 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2021, Andreas Kling * Copyright (c) 2022-2023, MacDue - * Copyright (c) 2023, Sam Atkins + * Copyright (c) 2023-2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -100,9 +101,9 @@ ErrorOr Process::spawn(ProcessSpawnOptions const& options) pid_t pid; if (options.search_for_executable_in_path) { - pid = TRY(System::posix_spawnp(options.executable.view(), &spawn_actions, nullptr, const_cast(argv_list.get().data()), System::environment())); + pid = TRY(System::posix_spawnp(options.executable.view(), &spawn_actions, nullptr, const_cast(argv_list.get().data()), Core::Environment::raw_environ())); } else { - pid = TRY(System::posix_spawn(options.executable.view(), &spawn_actions, nullptr, const_cast(argv_list.get().data()), System::environment())); + pid = TRY(System::posix_spawn(options.executable.view(), &spawn_actions, nullptr, const_cast(argv_list.get().data()), Core::Environment::raw_environ())); } return Process { pid }; } diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 94a3ef8b68..2eef1f1261 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2021-2022, Andreas Kling * Copyright (c) 2021-2022, Kenneth Myhra - * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * Copyright (c) 2022, Matthias Zimmerman * * SPDX-License-Identifier: BSD-2-Clause @@ -48,7 +48,6 @@ static int memfd_create(char const* name, unsigned int flags) #endif #if defined(AK_OS_MACOS) -# include # include # include #else @@ -1749,15 +1748,6 @@ ErrorOr resolve_executable_from_environment(StringView filename, int fla return Error::from_errno(ENOENT); } -char** environment() -{ -#if defined(AK_OS_MACOS) - return *_NSGetEnviron(); -#else - return environ; -#endif -} - ErrorOr current_executable_path() { char path[4096] = {}; diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 799e9ee501..48e75707e0 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2021, Andreas Kling * Copyright (c) 2021-2022, Kenneth Myhra - * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -274,8 +274,6 @@ ErrorOr posix_fallocate(int fd, off_t offset, off_t length); ErrorOr resolve_executable_from_environment(StringView filename, int flags = 0); -char** environment(); - ErrorOr current_executable_path(); ErrorOr allocate(size_t count, size_t size);