From patchwork Tue Mar 11 12:24:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 329062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B8782C00AB for ; Tue, 11 Mar 2014 23:27:11 +1100 (EST) Received: from localhost ([::1]:54361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNLm0-0003s7-K9 for incoming@patchwork.ozlabs.org; Tue, 11 Mar 2014 08:27:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48563) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNLka-0001BV-Ds for qemu-devel@nongnu.org; Tue, 11 Mar 2014 08:25:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNLkT-0004WX-Rt for qemu-devel@nongnu.org; Tue, 11 Mar 2014 08:25:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNLkT-0004WO-8i for qemu-devel@nongnu.org; Tue, 11 Mar 2014 08:25:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2BCOVaY026534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Mar 2014 08:24:32 -0400 Received: from localhost.localdomain.com (vpn1-6-106.ams2.redhat.com [10.36.6.106]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2BCOQxR007698; Tue, 11 Mar 2014 08:24:29 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Tue, 11 Mar 2014 14:24:48 +0200 Message-Id: <1394540689-26672-2-git-send-email-marcel.a@redhat.com> In-Reply-To: <1394540689-26672-1-git-send-email-marcel.a@redhat.com> References: <1394540689-26672-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com, aliguori@amazon.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH V3 1/2] tests/libqtest: Fix possible deadlock in qtest initialization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 'socket_accept' waits for Qemu to initialize 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 --- 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;