mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
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:
parent
ce374793bf
commit
082aecec87
1 changed files with 16 additions and 7 deletions
23
src/main.rs
23
src/main.rs
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue