[Libguestfs] [PATCH] daemon: initrd: print return value from failing process
Richard W.M. Jones
rjones at redhat.com
Tue Sep 15 08:32:08 UTC 2015
On Tue, Sep 15, 2015 at 10:20:11AM +0200, Pino Toscano wrote:
> 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 ac14826..c9fc2dd 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/<path> | 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;
> }
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
More information about the Libguestfs
mailing list