[PATCH] lib/qemu.c: Dump qemu's stderr if QMP test fails
Qemu will refuse to start on some (all?) architectures if firmware files are missing, or for other reasons, and complain to stderr. Those messages should be made visible to the user as part of the error message. --- lib/qemu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/qemu.c b/lib/qemu.c index 9edbe8208..483b772a4 100644 --- a/lib/qemu.c +++ b/lib/qemu.c @@ -68,6 +68,7 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) size_t allocsize = 0; ssize_t len; unsigned lineno; + CLEANUP_FREE_STRING_LIST char **err_lines = NULL; guestfs_int_cmd_add_string_unquoted (cmd, "echo "); /* QMP is modal. You have to send the qmp_capabilities command first. */ @@ -109,6 +110,11 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) if (len == -1 || strstr (line, "\"QMP\"") == NULL) { parse_failure: error (g, "did not understand QMP monitor output from %s", g->hv); + output_stderr: + err_lines = guestfs_int_split_string ('\n', guestfs_int_cmd_get_pipe_errors (cmd)); + if (err_lines) error (g, "stderr from %s:", g->hv); + for (int i=0; err_lines[i]; i++) + error (g, "%s", err_lines[i]); return -1; } @@ -134,7 +140,7 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) /* QMP tests are optional, don't fail if the tests fail. */ if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0) { error (g, "%s wait failed or unexpected exit status", g->hv); - return -1; + goto output_stderr; } return 0; -- 2.47.3
You can't call error multiple times on error paths, however it would work fine as a debug message, so how about the variation below? Rich. From 9eb1c5fd827739d24f916bcd1f9f0b2f98e4bdc8 Mon Sep 17 00:00:00 2001 From: Hilko Bengen <bengen@hilluzination.de> Date: Mon, 16 Feb 2026 19:40:33 +0100 Subject: [PATCH] lib/qemu.c: Dump qemu's stderr if QMP test fails Qemu will refuse to start on some (all?) architectures if firmware files are missing, or for other reasons, and complain to stderr. Those messages should be made visible to the user as part of the error message. --- lib/qemu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/qemu.c b/lib/qemu.c index 9edbe8208..09225c5c1 100644 --- a/lib/qemu.c +++ b/lib/qemu.c @@ -109,6 +109,16 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) if (len == -1 || strstr (line, "\"QMP\"") == NULL) { parse_failure: error (g, "did not understand QMP monitor output from %s", g->hv); + output_stderr: + int i; + CLEANUP_FREE_STRING_LIST char **err_lines = + guestfs_int_split_string ('\n', + guestfs_int_cmd_get_pipe_errors (cmd)); + if (err_lines) { + debug (g, "stderr from %s:", g->hv); + for (i=0; err_lines[i]; i++) + debug (g, "%s", err_lines[i]); + } return -1; } @@ -134,7 +144,7 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) /* QMP tests are optional, don't fail if the tests fail. */ if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0) { error (g, "%s wait failed or unexpected exit status", g->hv); - return -1; + goto output_stderr; } return 0; -- 2.52.0 -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com nbdkit - Flexible, fast NBD server with plugins https://gitlab.com/nbdkit/nbdkit
Or even better this version which will add the qemu stderr to the error message. Rich. From 7d39462ae81e04d5e50f6a2b37b8b4369c3fc5d4 Mon Sep 17 00:00:00 2001 From: Hilko Bengen <bengen@hilluzination.de> Date: Mon, 16 Feb 2026 19:40:33 +0100 Subject: [PATCH] lib/qemu.c: Dump qemu's stderr if QMP test fails Qemu will refuse to start on some (all?) architectures if firmware files are missing, or for other reasons, and complain to stderr. Those messages should be made visible to the user as part of the error message. --- lib/qemu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/qemu.c b/lib/qemu.c index 9edbe8208..a26e8c438 100644 --- a/lib/qemu.c +++ b/lib/qemu.c @@ -68,6 +68,8 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) size_t allocsize = 0; ssize_t len; unsigned lineno; + const char *errmsg; + CLEANUP_FREE char *errors = NULL; guestfs_int_cmd_add_string_unquoted (cmd, "echo "); /* QMP is modal. You have to send the qmp_capabilities command first. */ @@ -108,8 +110,8 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) if (len >= 0) debug (g, "generic_qmp_test: %u: %s", lineno, line); if (len == -1 || strstr (line, "\"QMP\"") == NULL) { parse_failure: - error (g, "did not understand QMP monitor output from %s", g->hv); - return -1; + errmsg = "did not understand QMP monitor output"; + goto err; } lineno++; /* line 2 */ @@ -133,11 +135,16 @@ generic_qmp_test (guestfs_h *g, const char *qmp_command, char **outp) r = guestfs_int_cmd_pipe_wait (cmd); /* QMP tests are optional, don't fail if the tests fail. */ if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0) { - error (g, "%s wait failed or unexpected exit status", g->hv); - return -1; + errmsg = "wait failed or unexpected exit status"; + goto err; } return 0; + + err: + errors = guestfs_int_cmd_get_pipe_errors (cmd); + error (g, "%s: %s\nError output of qemu: %s", g->hv, errmsg, errors); + return -1; } /** -- 2.52.0 -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com nbdkit - Flexible, fast NBD server with plugins https://gitlab.com/nbdkit/nbdkit
On Mon, Feb 16, 2026 at 10:43:33PM +0100, Hilko Bengen wrote:
* Richard W.M. Jones:
Or even better this version which will add the qemu stderr to the error message.
Sure, this is good.
No probs, this is upstream in 5a4977fc6 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (2)
-
Hilko Bengen -
Richard W.M. Jones