lib: flatten extra output when external command fails

Otherwise string output looks quite awkward

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson
2025-05-20 13:33:26 -04:00
committed by rwmjones
parent 3c1aebff81
commit 406588d4a0

View File

@@ -536,18 +536,25 @@ guestfs_int_external_command_failed (guestfs_h *g, int status,
{ {
const size_t len = 80 + strlen (cmd_name); const size_t len = 80 + strlen (cmd_name);
CLEANUP_FREE char *status_string = safe_malloc (g, len); CLEANUP_FREE char *status_string = safe_malloc (g, len);
CLEANUP_FREE char *extra_clean = NULL;
guestfs_int_exit_status_to_string (status, cmd_name, status_string, len); guestfs_int_exit_status_to_string (status, cmd_name, status_string, len);
if (extra) {
extra_clean = guestfs_int_replace_string(extra, "\n", " ");
if (!extra_clean)
g->abort_cb ();
}
if (g->verbose) { if (g->verbose) {
if (!extra) if (!extra_clean)
error (g, _("%s, see debug messages above"), status_string); error (g, _("%s, see debug messages above"), status_string);
else else
error (g, _("%s: %s: %s, see debug messages above"), error (g, _("%s: %s: %s, see debug messages above"),
cmd_name, extra, status_string); cmd_name, extra_clean, status_string);
} }
else { else {
if (!extra) if (!extra_clean)
error (g, _("%s.\n" error (g, _("%s.\n"
"To see full error messages you may need to enable debugging.\n" "To see full error messages you may need to enable debugging.\n"
DEBUG_ADVICE), DEBUG_ADVICE),
@@ -556,6 +563,6 @@ guestfs_int_external_command_failed (guestfs_h *g, int status,
error (g, _("%s: %s: %s.\n" error (g, _("%s: %s: %s.\n"
"To see full error messages you may need to enable debugging.\n" "To see full error messages you may need to enable debugging.\n"
DEBUG_ADVICE), DEBUG_ADVICE),
cmd_name, extra, status_string); cmd_name, extra_clean, status_string);
} }
} }