diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index fb3d39c194c..cd866dfc055 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -59,9 +59,11 @@ Application::~Application() void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url) { +#ifndef AK_OS_WINDOWS // Increase the open file limit, as the default limits on Linux cause us to run out of file descriptors with around 15 tabs open. if (auto result = Core::System::set_resource_limits(RLIMIT_NOFILE, 8192); result.is_error()) warnln("Unable to increase open file limit: {}", result.error()); +#endif Vector raw_urls; Vector certificates; diff --git a/Libraries/LibWebView/BrowserProcess.cpp b/Libraries/LibWebView/BrowserProcess.cpp index 1dfbf761299..f2a8296c2ea 100644 --- a/Libraries/LibWebView/BrowserProcess.cpp +++ b/Libraries/LibWebView/BrowserProcess.cpp @@ -40,15 +40,15 @@ ErrorOr BrowserProcess::connect(Vectorwrite_until_depleted(ByteString::number(::getpid()))); + TRY(m_pid_file->write_until_depleted(ByteString::number(Core::System::getpid()))); return ProcessDisposition::ContinueMainProcess; } ErrorOr BrowserProcess::connect_as_client(ByteString const& socket_path, Vector const& raw_urls, NewWindow new_window) { + // TODO: Mach IPC auto socket = TRY(Core::LocalSocket::connect(socket_path)); - static_assert(IsSame, "Need to handle other IPC transports here"); auto client = UIProcessClient::construct(IPC::Transport(move(socket))); if (new_window == NewWindow::Yes) { @@ -64,8 +64,7 @@ ErrorOr BrowserProcess::connect_as_client(ByteString const& socket_path, V ErrorOr BrowserProcess::connect_as_server(ByteString const& socket_path) { - static_assert(IsSame, "Need to handle other IPC transports here"); - + // TODO: Mach IPC auto socket_fd = TRY(Process::create_ipc_socket(socket_path)); m_socket_path = socket_path; auto local_server = TRY(Core::LocalServer::try_create()); diff --git a/Libraries/LibWebView/Process.cpp b/Libraries/LibWebView/Process.cpp index e5ba8ebd6d9..2f31aece3be 100644 --- a/Libraries/LibWebView/Process.cpp +++ b/Libraries/LibWebView/Process.cpp @@ -27,7 +27,7 @@ Process::~Process() ErrorOr Process::spawn_and_connect_to_process(Core::ProcessSpawnOptions const& options) { - static_assert(IsSame, "Need to handle other IPC transports here"); + // TODO: Mach IPC int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -35,8 +35,8 @@ ErrorOr Process::spawn_and_connect_to_process(C ArmedScopeGuard guard_fd_0 { [&] { MUST(Core::System::close(socket_fds[0])); } }; ArmedScopeGuard guard_fd_1 { [&] { MUST(Core::System::close(socket_fds[1])); } }; - auto& file_actions = const_cast(options).file_actions; - file_actions.append(Core::FileAction::CloseFile { socket_fds[0] }); + // Note: Core::System::socketpair creates inheritable sockets both on Linux and Windows unless SOCK_CLOEXEC is specified. + TRY(Core::System::set_close_on_exec(socket_fds[0], true)); auto takeover_string = MUST(String::formatted("{}:{}", options.name, socket_fds[1])); TRY(Core::Environment::set("SOCKET_TAKEOVER"sv, takeover_string, Core::Environment::Overwrite::Yes)); @@ -50,6 +50,18 @@ ErrorOr Process::spawn_and_connect_to_process(C return ProcessAndIPCTransport { move(process), IPC::Transport(move(ipc_socket)) }; } +#ifdef AK_OS_WINDOWS +// FIXME: Implement WebView::Process::get_process_pid on Windows +ErrorOr> Process::get_process_pid(StringView, StringView) +{ + VERIFY(0 && "WebView::Process::get_process_pid is not implemented"); +} +// FIXME: Implement WebView::Process::create_ipc_socket on Windows +ErrorOr Process::create_ipc_socket(ByteString const&) +{ + VERIFY(0 && "WebView::Process::create_ipc_socket is not implemented"); +} +#else ErrorOr> Process::get_process_pid(StringView process_name, StringView pid_path) { if (Core::System::stat(pid_path).is_error()) @@ -92,19 +104,19 @@ ErrorOr Process::create_ipc_socket(ByteString const& socket_path) if (!Core::System::stat(socket_path).is_error()) TRY(Core::System::unlink(socket_path)); -#ifdef SOCK_NONBLOCK +# ifdef SOCK_NONBLOCK auto socket_fd = TRY(Core::System::socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)); -#else +# else auto socket_fd = TRY(Core::System::socket(AF_LOCAL, SOCK_STREAM, 0)); int option = 1; TRY(Core::System::ioctl(socket_fd, FIONBIO, &option)); TRY(Core::System::fcntl(socket_fd, F_SETFD, FD_CLOEXEC)); -#endif +# endif -#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_GNU_HURD) +# if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_GNU_HURD) TRY(Core::System::fchmod(socket_fd, 0600)); -#endif +# endif auto socket_address = Core::SocketAddress::local(socket_path); auto socket_address_un = socket_address.to_sockaddr_un().release_value(); @@ -114,6 +126,7 @@ ErrorOr Process::create_ipc_socket(ByteString const& socket_path) return socket_fd; } +#endif ErrorOr Process::paths_for_process(StringView process_name) { diff --git a/Libraries/LibWebView/ProcessManager.cpp b/Libraries/LibWebView/ProcessManager.cpp index 8114cba2fd1..10e1b41c188 100644 --- a/Libraries/LibWebView/ProcessManager.cpp +++ b/Libraries/LibWebView/ProcessManager.cpp @@ -50,6 +50,8 @@ StringView process_name_from_type(ProcessType type) ProcessManager::ProcessManager() : on_process_exited([](Process&&) { }) { + // FIXME: Handle exiting child processes on Windows +#ifndef AK_OS_WINDOWS m_signal_handle = Core::EventLoop::register_signal(SIGCHLD, [this](int) { auto result = Core::System::waitpid(-1, WNOHANG); while (!result.is_error() && result.value().pid > 0) { @@ -61,6 +63,7 @@ ProcessManager::ProcessManager() result = Core::System::waitpid(-1, WNOHANG); } }); +#endif add_process(Process(WebView::ProcessType::Browser, nullptr, Core::Process::current())); @@ -74,7 +77,10 @@ ProcessManager::ProcessManager() ProcessManager::~ProcessManager() { + // FIXME: Handle exiting child processes on Windows +#ifndef AK_OS_WINDOWS Core::EventLoop::unregister_signal(m_signal_handle); +#endif } Optional ProcessManager::find_process(pid_t pid) diff --git a/Libraries/LibWebView/Utilities.cpp b/Libraries/LibWebView/Utilities.cpp index 9f5350cd25d..210b1e7bc66 100644 --- a/Libraries/LibWebView/Utilities.cpp +++ b/Libraries/LibWebView/Utilities.cpp @@ -104,7 +104,7 @@ ErrorOr> get_paths_for_helper_process(StringView process_name auto application_path = TRY(application_directory()); Vector paths; -#if !defined(AK_OS_MACOS) +#if !defined(AK_OS_MACOS) && !defined(AK_OS_WINDOWS) auto prefix = find_prefix(LexicalPath(application_path)); TRY(paths.try_append(LexicalPath::join(prefix.string(), libexec_path, process_name).string())); TRY(paths.try_append(LexicalPath::join(prefix.string(), "bin"sv, process_name).string()));