Ladybird/WebDriver: Retrieve process environment in an OS-dependent way

This commit is contained in:
Timothy Flynn 2022-12-15 13:36:21 -05:00 committed by Andrew Kaster
parent e5192073d9
commit 03294b0177
Notes: sideshowbarker 2024-07-17 02:37:56 +09:00

View file

@ -7,6 +7,7 @@
#define AK_DONT_REPLACE_STD
#include "../Utilities.h"
#include <AK/Platform.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Directory.h>
#include <LibCore/EventLoop.h>
@ -16,8 +17,22 @@
#include <LibMain/Main.h>
#include <WebDriver/Client.h>
#if defined(AK_OS_MACOS)
# include <crt_externs.h>
#endif
extern DeprecatedString s_serenity_resource_root;
static char** environment()
{
#if defined(AK_OS_MACOS)
return *_NSGetEnviron();
#else
extern char** environ;
return environ;
#endif
}
static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path)
{
char const* argv[] = {
@ -27,7 +42,7 @@ static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path)
nullptr,
};
return Core::System::posix_spawn("./ladybird"sv, nullptr, nullptr, const_cast<char**>(argv), environ);
return Core::System::posix_spawn("./ladybird"sv, nullptr, nullptr, const_cast<char**>(argv), environment());
}
static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_path)
@ -50,7 +65,7 @@ static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_pat
nullptr,
};
return Core::System::posix_spawn("./_deps/lagom-build/headless-browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ);
return Core::System::posix_spawn("./_deps/lagom-build/headless-browser"sv, nullptr, nullptr, const_cast<char**>(argv), environment());
}
ErrorOr<int> serenity_main(Main::Arguments arguments)