[Libguestfs] [PATCH v2 2/4] conn: Make sure we display all log messages when qemu goes away.

Richard W.M. Jones rjones at redhat.com
Fri Aug 9 21:51:01 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

If qemu goes away it is (more in theory than in reality) possible for
log messages to be lost in the kernel's socket buffer.

This turns out to matter more for User-Mode Linux.
---
 src/conn-socket.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/conn-socket.c b/src/conn-socket.c
index 2b3f222..aa66e3d 100644
--- a/src/conn-socket.c
+++ b/src/conn-socket.c
@@ -169,12 +169,22 @@ read_data (guestfs_h *g, struct connection *connv, void *bufv, size_t len)
         if (errno == EINTR || errno == EAGAIN)
           continue;
         if (errno == ECONNRESET) /* essentially the same as EOF case */
-          return 0;
+          goto closed;
         perrorf (g, "read_data: read");
         return -1;
       }
-      if (n == 0)
+      if (n == 0) {
+      closed:
+        /* Even though qemu has gone away, there could be more log
+         * messages in the console socket buffer in the kernel.  Read
+         * them out here.
+         */
+        if (g->verbose && conn->console_sock >= 0) {
+          while (handle_log_message (g, conn) == 1)
+            ;
+        }
         return 0;
+      }
 
       buf += n;
       len -= n;
-- 
1.8.3.1




More information about the Libguestfs mailing list