Skip to content

Commit

Permalink
try errno fun
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha committed Dec 23, 2023
1 parent 5303eb8 commit 41fc60e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mirrord/layer/src/detour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ impl<S> Try for Detour<S> {

fn branch(self) -> std::ops::ControlFlow<Self::Residual, Self::Output> {
match self {
Detour::Success(s) => core::ops::ControlFlow::Continue(s),
Detour::Success(s) => {
errno::set_errno(errno::Errno(0));
core::ops::ControlFlow::Continue(s)
}
Detour::Bypass(b) => core::ops::ControlFlow::Break(Detour::Bypass(b)),
Detour::Error(e) => core::ops::ControlFlow::Break(Detour::Error(e)),
}
Expand Down Expand Up @@ -348,7 +351,11 @@ where
/// - `Error` -> Convert to libc value and return it.
pub(crate) fn unwrap_or_bypass_with<F: FnOnce(Bypass) -> S>(self, op: F) -> S {
match self {
Detour::Success(s) => s,
Detour::Success(s) => {
// in case we edited errno, reset it to 0
errno::set_errno(errno::Errno(0));
s
}
Detour::Bypass(b) => op(b),
Detour::Error(e) => e.into(),
}
Expand All @@ -361,7 +368,11 @@ where
/// `Error` -> Convert to libc value and return it.
pub(crate) fn unwrap_or_bypass(self, value: S) -> S {
match self {
Detour::Success(s) => s,
Detour::Success(s) => {
// in case we edited errno, reset it to 0
errno::set_errno(errno::Errno(0));
s
}
Detour::Bypass(_) => value,
Detour::Error(e) => e.into(),
}
Expand Down

0 comments on commit 41fc60e

Please sign in to comment.