qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization
@ 2014-03-11 13:00 Marcel Apfelbaum
  2014-03-11 18:51 ` Stefan Hajnoczi
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Apfelbaum @ 2014-03-11 13:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, stefanha, armbru, aliguori, afaerber

'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.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 tests/libqtest.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index f587d36..c9e78aa 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;
@@ -147,12 +152,16 @@ QTestState *qtest_init(const char *extra_args)
     }
 
     s->fd = socket_accept(sock);
-    s->qmp_fd = socket_accept(qmpsock);
+    if (s->fd >= 0) {
+        s->qmp_fd = socket_accept(qmpsock);
+    }
     unlink(socket_path);
     unlink(qmp_socket_path);
     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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization
  2014-03-11 13:00 [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization Marcel Apfelbaum
@ 2014-03-11 18:51 ` Stefan Hajnoczi
  2014-03-11 19:20   ` Marcel Apfelbaum
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 18:51 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: kwolf, stefanha, qemu-devel, armbru, aliguori, afaerber

On Tue, Mar 11, 2014 at 03:00:34PM +0200, Marcel Apfelbaum wrote:
> '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.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> ---
>  tests/libqtest.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization
  2014-03-11 18:51 ` Stefan Hajnoczi
@ 2014-03-11 19:20   ` Marcel Apfelbaum
  2014-03-12  8:38     ` Stefan Hajnoczi
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Apfelbaum @ 2014-03-11 19:20 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kwolf, stefanha, qemu-devel, armbru, aliguori, afaerber

On Tue, 2014-03-11 at 19:51 +0100, Stefan Hajnoczi wrote:
> On Tue, Mar 11, 2014 at 03:00:34PM +0200, Marcel Apfelbaum wrote:
> > '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.
> > 
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > ---
> >  tests/libqtest.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

Thanks for the help, Stefan!
Please be aware that until you take care of the
"abort during qtest_init" issue, qtest will crash
on such occasions.

Last thing,  which maintainer should take this?
Thanks,
Marcel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization
  2014-03-11 19:20   ` Marcel Apfelbaum
@ 2014-03-12  8:38     ` Stefan Hajnoczi
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-03-12  8:38 UTC (permalink / raw)
  To: Marcel Apfelbaum
  Cc: kwolf, Stefan Hajnoczi, qemu-devel, armbru, aliguori, afaerber

On Tue, Mar 11, 2014 at 09:20:55PM +0200, Marcel Apfelbaum wrote:
> On Tue, 2014-03-11 at 19:51 +0100, Stefan Hajnoczi wrote:
> > On Tue, Mar 11, 2014 at 03:00:34PM +0200, Marcel Apfelbaum wrote:
> > > '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.
> > > 
> > > Reviewed-by: Eric Blake <eblake@redhat.com>
> > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > > ---
> > >  tests/libqtest.c | 13 +++++++++++--
> > >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 
> Thanks for the help, Stefan!
> Please be aware that until you take care of the
> "abort during qtest_init" issue, qtest will crash
> on such occasions.
> 
> Last thing,  which maintainer should take this?

Andreas Färber is the most likely victim^H^H^H^H^H^Hmaintainer:

"I don't feel like the official qtest maintainer, but I care and am
actively working on it. I would consider it best to have individual
tests maintained by subsystem maintainers and only define a maintainer
for the core libqtest.c/qtest.c code."

Although I'm interested in libqtest myself I don't have the bandwidth to
review/merge all future patches in that area.

Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-12  8:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-11 13:00 [Qemu-devel] [PATCH V4] tests/libqtest: Fix possible deadlock in qtest initialization Marcel Apfelbaum
2014-03-11 18:51 ` Stefan Hajnoczi
2014-03-11 19:20   ` Marcel Apfelbaum
2014-03-12  8:38     ` Stefan Hajnoczi

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).