Ladybird: Close the other side's file descriptors after forking

When spawning a WebContent process, we have to close the file
descriptors belonging to the "other side" in both processes, or they
will not get naturally "cleaned up" when one of the processes exits.

Fixes #93
This commit is contained in:
Andreas Kling 2022-10-08 11:01:59 +02:00 committed by Andrew Kaster
commit 52a7282c64
Notes: sideshowbarker 2024-07-17 02:41:29 +09:00

View file

@ -563,6 +563,9 @@ void WebContentView::create_client()
auto child_pid = fork();
if (!child_pid) {
MUST(Core::System::close(ui_fd_passing_fd));
MUST(Core::System::close(ui_fd));
auto takeover_string = String::formatted("x:{}", wc_fd);
MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
@ -577,6 +580,9 @@ void WebContentView::create_client()
VERIFY_NOT_REACHED();
}
MUST(Core::System::close(wc_fd_passing_fd));
MUST(Core::System::close(wc_fd));
auto socket = MUST(Core::Stream::LocalSocket::adopt_fd(ui_fd));
MUST(socket->set_blocking(true));