diff --git a/mirrord/layer/src/detour.rs b/mirrord/layer/src/detour.rs index 8d87ec4823d..8664d67129c 100644 --- a/mirrord/layer/src/detour.rs +++ b/mirrord/layer/src/detour.rs @@ -237,7 +237,10 @@ impl Try for Detour { fn branch(self) -> std::ops::ControlFlow { 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)), } @@ -348,7 +351,11 @@ where /// - `Error` -> Convert to libc value and return it. pub(crate) fn unwrap_or_bypass_with 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(), } @@ -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(), }