From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com,
aliguori@amazon.com, afaerber@suse.de
Subject: [Qemu-devel] [PATCH V2 1/2] tests/libqtest: Fix possible deadlock in qtest initialization
Date: Tue, 11 Mar 2014 12:09:09 +0200 [thread overview]
Message-ID: <1394532550-21857-2-git-send-email-marcel.a@redhat.com> (raw)
In-Reply-To: <1394532550-21857-1-git-send-email-marcel.a@redhat.com>
'socket_accept' waits for Qemu to init its unix socket.
If Qemu encounters an error during command line parsing,
it can exit before initializing the communication channel.
Using a timeout for sockets fixes the issue.
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
tests/libqtest.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index f587d36..f1ba254 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -34,6 +34,7 @@
#include "qapi/qmp/json-parser.h"
#define MAX_IRQ 256
+#define SOCKET_TIMEOUT 5
QTestState *global_qtest;
@@ -78,12 +79,16 @@ static int socket_accept(int sock)
struct sockaddr_un addr;
socklen_t addrlen;
int ret;
+ struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
+ .tv_usec = 0 };
+
+ setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout,
+ sizeof(timeout));
addrlen = sizeof(addr);
do {
ret = accept(sock, (struct sockaddr *)&addr, &addrlen);
} while (ret == -1 && errno == EINTR);
- g_assert_no_errno(ret);
close(sock);
return ret;
@@ -91,7 +96,7 @@ static int socket_accept(int sock)
static void kill_qemu(QTestState *s)
{
- if (s->qemu_pid != -1) {
+ if (s && s->qemu_pid != -1) {
kill(s->qemu_pid, SIGTERM);
waitpid(s->qemu_pid, NULL, 0);
}
@@ -153,6 +158,8 @@ QTestState *qtest_init(const char *extra_args)
g_free(socket_path);
g_free(qmp_socket_path);
+ g_assert(s->fd >= 0 && s->qmp_fd >= 0);
+
s->rx = g_string_new("");
for (i = 0; i < MAX_IRQ; i++) {
s->irq_level[i] = false;
--
1.8.3.1
next prev parent reply other threads:[~2014-03-11 10:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-11 10:09 [Qemu-devel] [PATCH V2 0/2] tests: Fix possible deadlock in qtest initialization Marcel Apfelbaum
2014-03-11 10:09 ` Marcel Apfelbaum [this message]
2014-03-11 12:40 ` [Qemu-devel] [PATCH V2 1/2] tests/libqtest: " Stefan Hajnoczi
2014-03-11 12:51 ` Marcel Apfelbaum
2014-03-11 13:04 ` Marcel Apfelbaum
2014-03-11 18:50 ` Stefan Hajnoczi
2014-03-11 10:09 ` [Qemu-devel] [PATCH V2 2/2] tests: Tweak the Makefile to produce per-test output Marcel Apfelbaum
2014-03-11 12:07 ` Eric Blake
2014-03-11 12:27 ` Marcel Apfelbaum
2014-03-11 12:45 ` Stefan Hajnoczi
2014-03-11 12:52 ` Marcel Apfelbaum
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=1394532550-21857-2-git-send-email-marcel.a@redhat.com \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).