From: "Richard W.M. Jones" <rjones(a)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.
(cherry picked from commit 236415e33939803565ae88a9222d3bae56ea16f9)
---
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 1ad92cf..2d93f47 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