Skip to content

Commit

Permalink
Always capture stderr
Browse files Browse the repository at this point in the history
Output of the qemu process on stderr is only captured when running in
non-interactive mode. However, the error reporting infrastructure always
assumes that it is being captured. As a result, we may see a panic
instead of a proper error report when, for one reason or another, Qemu
fails to start (as an example).
Fix the issue by making sure to always capture stderr. I haven't found
any adverse effects of doing so in my admittedly limited testing.

Closes: danobi#70

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Aug 7, 2024
1 parent 71c7a95 commit 2417550
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ impl Qemu {
let mut c = Command::new(format!("qemu-system-{}", target.arch));

c.args(QEMU_DEFAULT_ARGS)
.stderr(Stdio::piped())
.arg("-serial")
.arg("mon:stdio")
.args(kvm_args(&target.arch))
Expand Down Expand Up @@ -696,10 +697,7 @@ impl Qemu {
// the standard streams of the parent. This is not what we want
// when running in non-interactive mode.
if !qemu.interactive() {
qemu.process
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
qemu.process.stdin(Stdio::null()).stdout(Stdio::piped());
}
Ok(qemu)
}
Expand Down Expand Up @@ -942,7 +940,7 @@ impl Qemu {
fn extract_child_stderr(child: &mut Child) -> String {
let mut err = String::new();

// unwrap() should never fail b/c we are capturing stdout
// unwrap() should never fail b/c we are capturing stderr
let mut stderr = child.stderr.take().unwrap();
if let Err(e) = stderr.read_to_string(&mut err) {
err += &format!("<failed to read child stderr: {}>", e);
Expand Down

0 comments on commit 2417550

Please sign in to comment.