xtask: watch for kernel panic in stdout too

Seems unclear whether kernel panics go to stdout or stderr, so do them
both.
reviewable/pr745/r1
Tamir Duberstein 1 year ago
parent 90cf13163b
commit de65ba0067
No known key found for this signature in database

@ -5,7 +5,8 @@ use std::{
fs::{copy, create_dir_all, metadata, File}, fs::{copy, create_dir_all, metadata, File},
io::{BufRead as _, BufReader, ErrorKind, Write as _}, io::{BufRead as _, BufReader, ErrorKind, Write as _},
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{Child, Command, Output, Stdio}, process::{Child, ChildStdin, Command, Output, Stdio},
sync::{Arc, Mutex},
thread, thread,
}; };
@ -462,32 +463,49 @@ pub fn run(opts: Options) -> Result<()> {
stderr, stderr,
.. ..
} = &mut qemu_child; } = &mut qemu_child;
let mut stdin = stdin.take().unwrap(); let stdin = stdin.take().unwrap();
let stdin = Arc::new(Mutex::new(stdin));
let stdout = stdout.take().unwrap(); let stdout = stdout.take().unwrap();
let stdout = BufReader::new(stdout); let stdout = BufReader::new(stdout);
let stderr = stderr.take().unwrap(); let stderr = stderr.take().unwrap();
let stderr = BufReader::new(stderr); let stderr = BufReader::new(stderr);
let stderr = thread::Builder::new() fn terminate_if_contains_kernel_panic(
.spawn(move || { line: &str,
for line in stderr.lines() { stdin: &Arc<Mutex<ChildStdin>>,
let line = line.context("failed to read line from stderr")?; ) -> anyhow::Result<()> {
eprintln!("{}", line);
// Try to get QEMU to exit on kernel panic; otherwise it might hang indefinitely.
if line.contains("end Kernel panic") { if line.contains("end Kernel panic") {
println!("kernel panic detected; terminating QEMU");
let mut stdin = stdin.lock().unwrap();
stdin stdin
.write_all(&[0x01, b'x']) .write_all(&[0x01, b'x'])
.context("failed to write to stdin")?; .context("failed to write to stdin")?;
println!("waiting for QEMU to terminate");
}
Ok(())
} }
let stderr = {
let stdin = stdin.clone();
thread::Builder::new()
.spawn(move || {
for line in stderr.lines() {
let line = line.context("failed to read line from stderr")?;
eprintln!("{}", line);
// Try to get QEMU to exit on kernel panic; otherwise it might hang indefinitely.
terminate_if_contains_kernel_panic(&line, &stdin)?;
} }
anyhow::Ok(()) anyhow::Ok(())
}) })
.unwrap(); .unwrap()
};
let mut outcome = None; let mut outcome = None;
for line in stdout.lines() { for line in stdout.lines() {
let line = line.context("failed to read line from stdout")?; let line = line.context("failed to read line from stdout")?;
println!("{}", line); println!("{}", line);
// Try to get QEMU to exit on kernel panic; otherwise it might hang indefinitely.
terminate_if_contains_kernel_panic(&line, &stdin)?;
// The init program will print "init: success" or "init: failure" to indicate // The init program will print "init: success" or "init: failure" to indicate
// the outcome of running the binaries it found in /bin. // the outcome of running the binaries it found in /bin.
if let Some(line) = line.strip_prefix("init: ") { if let Some(line) = line.strip_prefix("init: ") {

Loading…
Cancel
Save