diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-07-03 13:09:53 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-07 11:30:04 +0100 |
commit | b6ef5f47cf6355c860f659252a391293ae026a32 (patch) | |
tree | 56a94db043e38d936b76a2ba533a99104e43a52a /src | |
parent | ced9e9840715c8dab85465611fc566fc5d1a4df1 (diff) | |
download | libguestfs-b6ef5f47cf6355c860f659252a391293ae026a32.tar.gz libguestfs-b6ef5f47cf6355c860f659252a391293ae026a32.tar.xz libguestfs-b6ef5f47cf6355c860f659252a391293ae026a32.zip |
close: Warn if qemu exits unsuccessfully.
Currently guestfs_close has no method to return an error indication,
so this commit simply prints the error on stderr.
(cherry picked from commit bcc4ffb52b9f4b5db7861682905ec32844f4603b)
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/guestfs.c b/src/guestfs.c index 4e66e17e..d2c5b4eb 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -172,6 +172,8 @@ guestfs_create (void) void guestfs_close (guestfs_h *g) { + int status, sig; + if (g->state == NO_HANDLE) { /* Not safe to call ANY callbacks here, so ... */ fprintf (stderr, _("guestfs_close: called twice on the same handle\n")); @@ -228,7 +230,23 @@ guestfs_close (guestfs_h *g) g->sock = -1; /* Wait for subprocess(es) to exit. */ - if (g->pid > 0) waitpid (g->pid, NULL, 0); + if (g->pid > 0) { + if (waitpid (g->pid, &status, 0) == -1) + perror ("waitpid (qemu)"); + if (WIFEXITED (status) && WEXITSTATUS (status) != 0) + fprintf (stderr, "libguestfs: close: qemu failed (status %d)\n", + WEXITSTATUS (status)); + else if (WIFSIGNALED (status)) { + sig = WTERMSIG (status); + fprintf (stderr, "libguestfs: close: qemu terminated by signal %d (%s)\n", + sig, strsignal (sig)); + } + else if (WIFSTOPPED (status)) { + sig = WSTOPSIG (status); + fprintf (stderr, "libguestfs: close: qemu stopped by signal %d (%s)\n", + sig, strsignal (sig)); + } + } if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0); /* Run user close callbacks. */ |