Skip to content

Commit 6d1d1ff

Browse files
committed
Fix Command::spawn: Skip set_blocking for inherited
Signed-off-by: Jiahao XU <[email protected]>
1 parent 139e070 commit 6d1d1ff

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/native_mux_impl/command.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,17 @@ impl Command {
7171
stderr.as_raw_fd_or_null_fd()?,
7272
];
7373

74-
for stdio in stdios {
75-
set_blocking(stdio).map_err(Error::ChildIo)?;
76-
}
74+
let is_inherited = [
75+
self.stdin_v.is_inherited(),
76+
self.stdout_v.is_inherited(),
77+
self.stderr_v.is_inherited(),
78+
];
79+
80+
stdios
81+
.into_iter()
82+
.zip(is_inherited)
83+
.filter_map(|(stdio, is_inherited)| if !is_inherited { Some(stdio) } else { None })
84+
.try_for_each(|stdio| set_blocking(stdio).map_err(Error::ChildIo))?;
7785

7886
let cmd = NonZeroByteSlice::new(&self.cmd).ok_or(Error::InvalidCommand)?;
7987

src/stdio.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ impl Stdio {
4343
pub const fn inherit() -> Self {
4444
Self(StdioImpl::Inherit)
4545
}
46+
47+
#[cfg(feature = "native-mux")]
48+
pub(super) fn is_inherited(&self) -> bool {
49+
matches!(self.0, StdioImpl::Inherit)
50+
}
4651
}
4752
impl FromRawFd for Stdio {
4853
unsafe fn from_raw_fd(fd: RawFd) -> Self {

0 commit comments

Comments
 (0)