From cd7459d608106b0427afa186ac95cda9ee296381 Mon Sep 17 00:00:00 2001 From: MacDue Date: Fri, 24 Mar 2023 21:55:23 +0000 Subject: [PATCH] LibCore: Get the environment in Core::Process::spawn() on macOS This is copied over from ladybird, but putting it here makes this more reusable. --- Userland/Libraries/LibCore/Process.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 32e43ba711..285973462c 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -21,7 +21,19 @@ # include #endif -extern char** environ; +#if defined(AK_OS_MACOS) +# include +#endif + +static char** environment() +{ +#if defined(AK_OS_MACOS) + return *_NSGetEnviron(); +#else + extern char** environ; + return environ; +#endif +} namespace Core { @@ -65,11 +77,11 @@ struct ArgvList { if (!m_working_directory.is_empty()) posix_spawn_file_actions_addchdir(&spawn_actions, m_working_directory.characters()); - auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast(get().data()), environ)); + auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast(get().data()), environment())); if (keep_as_child == Process::KeepAsChild::No) TRY(System::disown(pid)); #else - auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast(get().data()), environ)); + auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast(get().data()), environment())); // FIXME: Support keep_as_child outside Serenity. (void)keep_as_child; #endif