summaryrefslogtreecommitdiffstats
path: root/src/guestfs.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-07-03 13:09:53 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-03 18:14:06 +0100
commitbcc4ffb52b9f4b5db7861682905ec32844f4603b (patch)
tree0d316480ecc958b87f2249bc2542d27d32e86a35 /src/guestfs.c
parentfc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1 (diff)
downloadlibguestfs-bcc4ffb52b9f4b5db7861682905ec32844f4603b.tar.gz
libguestfs-bcc4ffb52b9f4b5db7861682905ec32844f4603b.tar.xz
libguestfs-bcc4ffb52b9f4b5db7861682905ec32844f4603b.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.
Diffstat (limited to 'src/guestfs.c')
-rw-r--r--src/guestfs.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 16d11dae..e36ad461 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. */