mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user