From: Anthony PERARD Subject: [PATCH V2] libxl_qmp: Handle unexpected end-of-socket Date: Mon, 20 Feb 2012 17:28:36 +0000 Message-ID: <1329758916-25379-1-git-send-email-anthony.perard@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen Devel Cc: Anthony PERARD , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org 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 --- change with v1: - remove the introduced goto in favor of a "continue". tools/libxl/libxl_qmp.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index e0642e3..a974afe 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -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; -- tg: (75f1fb7..) fix/qmp-end-of-socket (depends on: master)