Skip to content

Commit aff20bf

Browse files
authored
Update stderr.rFix setting O_NONBLOCK in parallel::stderr::set_non_blocking
fix #945
1 parent 0042c70 commit aff20bf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/parallel/stderr.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ pub fn set_non_blocking(stderr: &mut ChildStderr) -> Result<(), Error> {
1414
{
1515
use std::os::unix::io::AsRawFd;
1616
let fd = stderr.as_raw_fd();
17-
debug_assert_eq!(
18-
unsafe { libc::fcntl(fd, libc::F_GETFL, 0) },
19-
0,
20-
"stderr should have no flags set"
21-
);
17+
let flags = unsafe { libc::fcntl(fd, libc::F_GETFL, 0) };
18+
if flags == -1 {
19+
return Err(Error::new(
20+
ErrorKind::IOError,
21+
format!(
22+
"Failed to get flags for child stderr: {}",
23+
std::io::Error::last_os_error()
24+
),
25+
));
26+
}
2227

23-
if unsafe { libc::fcntl(fd, libc::F_SETFL, libc::O_NONBLOCK) } != 0 {
28+
if unsafe { libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK) } == -1 {
2429
return Err(Error::new(
2530
ErrorKind::IOError,
2631
format!(

0 commit comments

Comments
 (0)