RequestServer: Use Core::System::pipe2 for creating the request FDs

This causes a behavior change in which the read FD is now non-blocking.
This is intentional, as this change avoids a deadlock between RS and
WebContent, where WC could block while reading from the request FD,
while RS is blocked sending a message to WC.
This commit is contained in:
Timothy Flynn 2024-03-12 15:02:54 -04:00 committed by Tim Flynn
parent a973fe13cb
commit 644e764620
Notes: sideshowbarker 2024-07-17 07:08:37 +09:00

View file

@ -6,11 +6,8 @@
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
#include <LibCore/System.h>
#include <RequestServer/Protocol.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
namespace RequestServer {
@ -32,13 +29,7 @@ Protocol::Protocol(ByteString const& name)
ErrorOr<Protocol::Pipe> Protocol::get_pipe_for_request()
{
int fd_pair[2] { 0 };
if (pipe(fd_pair) != 0) {
auto saved_errno = errno;
dbgln("Protocol: pipe() failed: {}", strerror(saved_errno));
return Error::from_errno(saved_errno);
}
fcntl(fd_pair[1], F_SETFL, fcntl(fd_pair[1], F_GETFL) | O_NONBLOCK);
auto fd_pair = TRY(Core::System::pipe2(O_NONBLOCK));
return Pipe { fd_pair[0], fd_pair[1] };
}