diff options
author | Stephen Barber <smbarber@chromium.org> | 2017-10-30 19:55:39 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-10-31 19:50:44 -0700 |
commit | 082aecec87e818a971d7a2c3c548e8aaf4745bd6 (patch) | |
tree | 36f018cd503181637e177839a303b5d98584eeb9 /src/main.rs | |
parent | ce374793bf1b40838c7588620ac5b3784fa4997a (diff) | |
download | crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar.gz crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar.bz2 crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar.lz crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar.xz crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.tar.zst crosvm-082aecec87e818a971d7a2c3c548e8aaf4745bd6.zip |
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>
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index caaf3de..ac7350a 100644 --- a/src/main.rs +++ b/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 => { |