]> xenbits.xensource.com Git - people/vhanquez/xen.git/commitdiff
libxl_qmp: Handle unexpected end-of-socket
authorAnthony PERARD <anthony.perard@citrix.com>
Mon, 20 Feb 2012 17:53:33 +0000 (17:53 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Mon, 20 Feb 2012 17:53:33 +0000 (17:53 +0000)
When read() return 0, the current code just tries again. But this
leads to an infinite loop if QEMU died too soon.

Also, retry select if a signal was caught.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_qmp.c

index e0642e31b5980c6ad48b84a5b27ef11b20c340be..a974afecffa73306bd7aeef773e8b53da9abeebf 100644 (file)
@@ -390,13 +390,16 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR, "timeout");
             return -1;
         } else if (ret < 0) {
+            if (errno == EINTR)
+                continue;
             LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, "Select error");
             return -1;
         }
 
         rd = read(qmp->qmp_fd, qmp->buffer, QMP_RECEIVE_BUFFER_SIZE);
         if (rd == 0) {
-            continue;
+            LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR, "Unexpected end of socket");
+            return -1;
         } else if (rd < 0) {
             LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, "Socket read error");
             return rd;