From fd39fd4ab0d9915701a5ebce9bdbf66dc0b9c60f Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 22 Jan 2024 09:56:25 -0800 Subject: [PATCH] backend/rs: Retry send/recv on `EINTR` This could be considered a breaking API change, but probably no callers are actually handling it. And it seems libwayland does this, so making the rs backend consistent here can be considered a bug fix. --- wayland-backend/CHANGELOG.md | 2 ++ wayland-backend/src/rs/socket.rs | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wayland-backend/CHANGELOG.md b/wayland-backend/CHANGELOG.md index 08711335cdf..0787ddcc663 100644 --- a/wayland-backend/CHANGELOG.md +++ b/wayland-backend/CHANGELOG.md @@ -7,6 +7,8 @@ #### Bugfixes - backend/sys: Fix error/segfault if object argument is no longer alive +- backend/rs: Retry send/recv on `EINTR` + * Matches the behavior of libwayland ## 0.3.2 -- 2023-09-25 diff --git a/wayland-backend/src/rs/socket.rs b/wayland-backend/src/rs/socket.rs index f42c6db6ae1..c11607475fe 100644 --- a/wayland-backend/src/rs/socket.rs +++ b/wayland-backend/src/rs/socket.rs @@ -6,6 +6,7 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; use std::os::unix::net::UnixStream; use std::slice; +use rustix::io::retry_on_intr; use rustix::net::{ recvmsg, send, sendmsg, RecvAncillaryBuffer, RecvAncillaryMessage, RecvFlags, SendAncillaryBuffer, SendAncillaryMessage, SendFlags, @@ -51,9 +52,9 @@ impl Socket { let fds = unsafe { slice::from_raw_parts(fds.as_ptr() as *const BorrowedFd, fds.len()) }; cmsg_buffer.push(SendAncillaryMessage::ScmRights(fds)); - Ok(sendmsg(self, &iov, &mut cmsg_buffer, flags)?) + Ok(retry_on_intr(|| sendmsg(self, &iov, &mut cmsg_buffer, flags))?) } else { - Ok(send(self, bytes, flags)?) + Ok(retry_on_intr(|| send(self, bytes, flags))?) } } @@ -77,7 +78,7 @@ impl Socket { let mut cmsg_space = vec![0; rustix::cmsg_space!(ScmRights(MAX_FDS_OUT))]; let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut cmsg_space); let mut iov = [IoSliceMut::new(buffer)]; - let msg = recvmsg(&self.stream, &mut iov[..], &mut cmsg_buffer, flags)?; + let msg = retry_on_intr(|| recvmsg(&self.stream, &mut iov[..], &mut cmsg_buffer, flags))?; let received_fds = cmsg_buffer .drain()