From 082aecec87e818a971d7a2c3c548e8aaf4745bd6 Mon Sep 17 00:00:00 2001 From: Stephen Barber Date: Mon, 30 Oct 2017 19:55:39 -0700 Subject: [PATCH] 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 Tested-by: Stephen Barber Reviewed-by: Zach Reizner --- src/main.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index caaf3de6af..ac7350a2a7 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 => {