crosvm: remove stdin from pollables at EOF/error

If reading from stdin returns EOF or an error, remove it from the list
of pollables.

BUG=none
TEST=`vm_launcher start` and check that crosvm no longer pegs CPU

Change-Id: I7971058701e6145884de9c52a8dd5b829373637b
Reviewed-on: https://chromium-review.googlesource.com/745961
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Stephen Barber 2017-10-30 19:55:39 -07:00 committed by chrome-bot
parent ce374793bf
commit 082aecec87

View file

@ -713,13 +713,22 @@ fn run_control(mut vm: Vm,
}
STDIN => {
let mut out = [0u8; 64];
let count = stdin_lock.read_raw(&mut out[..]).unwrap_or_default();
if count != 0 {
stdio_serial
.lock()
.unwrap()
.queue_input_bytes(&out[..count])
.expect("failed to queue bytes into serial port");
match stdin_lock.read_raw(&mut out[..]) {
Ok(0) => {
// Zero-length read indicates EOF. Remove from pollables.
pollables.retain(|&pollable| pollable.0 != STDIN);
},
Err(e) => {
warn!("error while reading stdin: {:?}", e);
pollables.retain(|&pollable| pollable.0 != STDIN);
},
Ok(count) => {
stdio_serial
.lock()
.unwrap()
.queue_input_bytes(&out[..count])
.expect("failed to queue bytes into serial port");
},
}
}
CHILD_SIGNAL => {