Ladybird+LibIPC: Move clearing FD_CLOEXEC helper logic to IPC::File

This commit is contained in:
Andrew Kaster 2024-06-25 14:57:16 -06:00
parent 54f66c574c
commit 343a3a0d7e
Notes: sideshowbarker 2024-07-16 20:31:50 +09:00
2 changed files with 12 additions and 8 deletions

View File

@ -160,14 +160,7 @@ ErrorOr<IPC::File> connect_new_request_server_client(Protocol::RequestClient& cl
return Error::from_string_literal("Failed to connect to RequestServer");
auto socket = new_socket->take_client_socket();
// FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding.
// Perhaps we should add an option to IPC::File to allow the receiver to decide whether to
// make it O_CLOEXEC or not. Or an attribute in the .ipc file?
auto fd = socket.fd();
auto fd_flags = MUST(Core::System::fcntl(fd, F_GETFD));
fd_flags &= ~FD_CLOEXEC;
MUST(Core::System::fcntl(fd, F_SETFD, fd_flags));
TRY(socket.clear_close_on_exec());
return socket;
}

View File

@ -63,6 +63,17 @@ public:
return exchange(m_fd, -1);
}
// FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding.
// Perhaps we should add an option to IPC::File to allow the receiver to decide whether to
// make it O_CLOEXEC or not. Or an attribute in the .ipc file?
ErrorOr<void> clear_close_on_exec()
{
auto fd_flags = TRY(Core::System::fcntl(m_fd, F_GETFD));
fd_flags &= ~FD_CLOEXEC;
TRY(Core::System::fcntl(m_fd, F_SETFD, fd_flags));
return {};
}
private:
explicit File(int fd)
: m_fd(fd)