From 59a9101e44f727aef0ffdd11d3270031113baa11 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 15 Sep 2015 10:19:58 +0200 Subject: [PATCH] daemon: initrd: print return value from failing process If either zcat or cpio fails when spawned in initrd-list, pclose will return the actual return value of it, but reply_with_perror still uses errno regardless; thus, the reported error is: libguestfs: error: initrd_list: pclose: Success which is not much helpful. Instead, when pclose returns > 0, extract the actual return value of the subprocess, and print that. Thus now we get for example: libguestfs: error: initrd_list: pclose: command failed with return code 1 --- daemon/initrd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/daemon/initrd.c b/daemon/initrd.c index ac1482676..c9fc2ddae 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -43,6 +43,7 @@ do_initrd_list (const char *path) CLEANUP_FREE char *filename = NULL; size_t allocsize; ssize_t len; + int ret; /* "zcat /sysroot/ | cpio --quiet -it", but path must be quoted. */ if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path, str_cpio) == -1) { @@ -74,8 +75,15 @@ do_initrd_list (const char *path) return NULL; } - if (pclose (fp) != 0) { - reply_with_perror ("pclose"); + ret = pclose (fp); + if (ret != 0) { + if (ret == -1) + reply_with_perror ("pclose"); + else { + if (WEXITSTATUS (ret) != 0) + ret = WEXITSTATUS (ret); + reply_with_error ("pclose: command failed with return code %d", ret); + } free_stringslen (filenames.argv, filenames.size); return NULL; }