Skip to content

Commit 4c658f7

Browse files
committed
Update compiletest's read2 function
This was originally copied over from Cargo and Cargo has since [been updated][update] so let's pull in the fixes here too! [update]: rust-lang/cargo#5030
1 parent 16362c7 commit 4c658f7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/tools/compiletest/src/read2.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ mod imp {
5858
fds[0].events = libc::POLLIN;
5959
fds[1].fd = err_pipe.as_raw_fd();
6060
fds[1].events = libc::POLLIN;
61-
loop {
61+
let mut nfds = 2;
62+
let mut errfd = 1;
63+
64+
while nfds > 0 {
6265
// wait for either pipe to become readable using `select`
63-
let r = unsafe { libc::poll(fds.as_mut_ptr(), 2, -1) };
66+
let r = unsafe { libc::poll(fds.as_mut_ptr(), nfds, -1) };
6467
if r == -1 {
6568
let err = io::Error::last_os_error();
6669
if err.kind() == io::ErrorKind::Interrupted {
@@ -86,19 +89,20 @@ mod imp {
8689
}
8790
}
8891
};
89-
if !out_done && fds[0].revents != 0 && handle(out_pipe.read_to_end(&mut out))? {
90-
out_done = true;
91-
}
92-
data(true, &mut out, out_done);
93-
if !err_done && fds[1].revents != 0 && handle(err_pipe.read_to_end(&mut err))? {
92+
if !err_done && fds[errfd].revents != 0 && handle(err_pipe.read_to_end(&mut err))? {
9493
err_done = true;
94+
nfds -= 1;
9595
}
9696
data(false, &mut err, err_done);
97-
98-
if out_done && err_done {
99-
return Ok(())
97+
if !out_done && fds[0].revents != 0 && handle(out_pipe.read_to_end(&mut out))? {
98+
out_done = true;
99+
fds[0].fd = err_pipe.as_raw_fd();
100+
errfd = 0;
101+
nfds -= 1;
100102
}
103+
data(true, &mut out, out_done);
101104
}
105+
Ok(())
102106
}
103107
}
104108

0 commit comments

Comments
 (0)