From f910476dd7ae7b1a75ec8493b108328eb0183c8b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 9 Aug 2019 11:48:03 +0100 Subject: [PATCH] vmm: Only send stdin input to serial/console if it can handle it Do not send the contents of stdin to the serial or console device if they're not in tty mode. Signed-off-by: Rob Bradford --- vmm/src/config.rs | 9 +++++++++ vmm/src/vm.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 8181cc231..f40458274 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -352,6 +352,15 @@ pub enum ConsoleOutputMode { File, } +impl ConsoleOutputMode { + pub fn input_enabled(&self) -> bool { + match self { + ConsoleOutputMode::Tty => true, + _ => false, + } + } +} + pub struct ConsoleConfig<'a> { pub file: Option<&'a Path>, pub mode: ConsoleOutputMode, diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index e3ca92cbf..f1381eb99 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1489,7 +1489,9 @@ impl<'a> Vm<'a> { .read_raw(&mut out) .map_err(Error::Serial)?; - if self.devices.serial.is_some() { + if self.devices.serial.is_some() + && self.config.serial.mode.input_enabled() + { self.devices .serial .as_ref() @@ -1500,7 +1502,9 @@ impl<'a> Vm<'a> { .map_err(Error::Serial)?; } - if self.devices.console.is_some() { + if self.devices.console.is_some() + && self.config.console.mode.input_enabled() + { self.devices .console .as_ref()