From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN5Tf-0003wF-C7 for qemu-devel@nongnu.org; Mon, 10 Mar 2014 15:03:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WN5TZ-0000TJ-D5 for qemu-devel@nongnu.org; Mon, 10 Mar 2014 15:03:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN5TZ-0000T2-64 for qemu-devel@nongnu.org; Mon, 10 Mar 2014 15:03:01 -0400 Date: Mon, 10 Mar 2014 20:02:56 +0100 From: Stefan Hajnoczi Message-ID: <20140310190256.GA12263@stefanha-thinkpad.redhat.com> References: <1394453534-24334-1-git-send-email-marcel.a@redhat.com> <1394453534-24334-2-git-send-email-marcel.a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1394453534-24334-2-git-send-email-marcel.a@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] tests/libqtest: Fix possible deadlock in qtest initialization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum Cc: armbru@redhat.com, qemu-devel@nongnu.org, aliguori@amazon.com, afaerber@suse.de On Mon, Mar 10, 2014 at 02:12:13PM +0200, Marcel Apfelbaum wrote: > @@ -123,6 +125,11 @@ QTestState *qtest_init(const char *extra_args) > sock = init_socket(socket_path); > qmpsock = init_socket(qmp_socket_path); > > + setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&socket_timeout, > + sizeof(socket_timeout)); > + setsockopt(qmpsock, SOL_SOCKET, SO_RCVTIMEO, (void *)&socket_timeout, > + sizeof(socket_timeout)); > + Please move this into socket_accept() so qtest_init() doesn't need to know about setsockopt() details. It should just get an fd or -errno return value from socket_accept()... > 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); ...then you can ensure that we unlink the sockets even on failure. And then something like g_assert(s->fd >= 0 && s->qmp_fd >= 0) would be fine. The process can abort() at this point.