From: Anthony PERARD <anthony.perard@citrix.com>
To: Xen Devel <xen-devel@lists.xensource.com>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH] libxl_qmp: Handle unexpected end-of-socket
Date: Thu, 19 Jan 2012 15:35:22 +0000 [thread overview]
Message-ID: <1326987322-28007-1-git-send-email-anthony.perard@citrix.com> (raw)
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>
---
tools/libxl/libxl_qmp.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 1777e44..d3b1d53 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -385,18 +385,22 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
FD_ZERO(&rfds);
FD_SET(qmp->qmp_fd, &rfds);
+do_select_again:
ret = select(qmp->qmp_fd + 1, &rfds, NULL, NULL, &timeout);
if (ret == 0) {
LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR, "timeout");
return -1;
} else if (ret < 0) {
+ if (errno == EINTR)
+ goto do_select_again;
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: (6674c38..) fix/qmp-end-of-socket (depends on: master)
next reply other threads:[~2012-01-19 15:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-19 15:35 Anthony PERARD [this message]
2012-02-20 17:09 ` [PATCH] libxl_qmp: Handle unexpected end-of-socket Ian Jackson
2012-02-20 17:17 ` Anthony PERARD
2012-02-20 17:23 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326987322-28007-1-git-send-email-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).