vmm: Always reset the console mode on VMM exit

Tested:

1. SIGTERM based
2. VM shutdown/poweroff
3. Injected VM boot failure after calling Vm::setup_tty()

Fixes: #4248

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-06-28 16:01:08 +01:00
parent a26f86f8ad
commit 2e664dca64
2 changed files with 15 additions and 6 deletions

View File

@ -23,6 +23,7 @@ use thiserror::Error;
use vmm::config;
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::signal::block_signal;
use vmm_sys_util::terminal::Terminal;
#[derive(Error, Debug)]
enum Error {
@ -623,6 +624,13 @@ fn main() {
}
};
let on_tty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0;
if on_tty {
// Don't forget to set the terminal in canonical mode
// before to exit.
std::io::stdin().lock().set_canon_mode().unwrap();
}
std::process::exit(exit_code);
}

View File

@ -1694,13 +1694,14 @@ impl Vm {
console_input_clone.update_console_size();
}
SIGTERM | SIGINT => {
if exit_evt.write(1).is_err() {
// Resetting the terminal is usually done as the VMM exits
if on_tty {
io::stdin()
.lock()
.set_canon_mode()
.expect("failed to restore terminal mode");
}
if exit_evt.write(1).is_err() {
std::process::exit(1);
}
}