Skip to content

Commit

Permalink
Fixed wrong errno being set by mirrord (#1829)
Browse files Browse the repository at this point in the history
* Fixed wrong errno being set by mirrord, fixing various flows that rely on errno even when return code is ok

* ..
  • Loading branch information
aviramha authored Aug 22, 2023
1 parent 4eef744 commit 7885d36
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/1828.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed wrong errno being set by mirrord, fixing various flows that rely on errno even when return code is ok
2 changes: 1 addition & 1 deletion mirrord/layer/src/socket/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub(super) unsafe extern "C" fn recvmsg_detour(
) -> ssize_t {
let recvmsg_result = FN_RECVMSG(sockfd, message_header, flags);

if recvmsg_result == -1 && errno::errno() != errno::Errno(libc::EAGAIN) {
if recvmsg_result == -1 {
recvmsg_result
} else {
// Fills the address, similar to how `recv_from` works.
Expand Down
6 changes: 1 addition & 5 deletions mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,6 @@ pub(super) fn recv_from(
raw_source: *mut sockaddr,
source_length: *mut socklen_t,
) -> Detour<isize> {
if errno::errno() == errno::Errno(libc::EAGAIN) {
trace!("recvfrom/recvmsg hit EAGAIN, setting errno to 0");
errno::set_errno(errno::Errno(0));
}

SOCKETS
.get(&sockfd)
.and_then(|socket| match &socket.state {
Expand All @@ -931,6 +926,7 @@ pub(super) fn recv_from(
.map(SocketAddress::try_into)?
.map(|address| fill_address(raw_source, source_length, address))??;

errno::set_errno(errno::Errno(0));
Detour::Success(recv_from_result)
}

Expand Down

0 comments on commit 7885d36

Please sign in to comment.