From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEJzn-0008JZ-Tc for qemu-devel@nongnu.org; Fri, 14 Feb 2014 09:44:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WEJzi-0008Q3-8Y for qemu-devel@nongnu.org; Fri, 14 Feb 2014 09:44:03 -0500 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:52757) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEJzi-0008Pt-2Q for qemu-devel@nongnu.org; Fri, 14 Feb 2014 09:43:58 -0500 Received: by mail-wg0-f41.google.com with SMTP id l18so418974wgh.0 for ; Fri, 14 Feb 2014 06:43:57 -0800 (PST) Date: Fri, 14 Feb 2014 15:43:54 +0100 From: Stefan Hajnoczi Message-ID: <20140214144354.GJ17391@stefanha-thinkpad.redhat.com> References: <1391944901-23475-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1391944901-23475-1-git-send-email-afaerber@suse.de> Subject: Re: [Qemu-devel] [PATCH] qtest: Unlink pid file before reading from QMP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, Stefan Hajnoczi On Sun, Feb 09, 2014 at 12:21:41PM +0100, Andreas Färber wrote: > Despite 1ad3c6abc0d67e00b84abaa5527bc64b70ca2205, supplying invalid > arguments to the QEMU process still leaked a /tmp/qtest-*.pid file. > > Fix this by reordering the reading and unlinking to before reading from > QMP socket, which relies on a running process. > > Cc: Stefan Hajnoczi > Signed-off-by: Andreas Färber > --- > tests/libqtest.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tests/libqtest.c b/tests/libqtest.c > index c9a4f89..9433782 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -157,14 +157,14 @@ QTestState *qtest_init(const char *extra_args) > s->irq_level[i] = false; > } > > - /* Read the QMP greeting and then do the handshake */ > - qtest_qmp_discard_response(s, ""); > - qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); > - > s->qemu_pid = read_pid_file(pid_file); > unlink(pid_file); > g_free(pid_file); > > + /* Read the QMP greeting and then do the handshake */ > + qtest_qmp_discard_response(s, ""); > + qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); > + Hmm...the original ordering was intentional. In order to avoid race conditions between QEMU creating the pid file and qtest reading the pid file, we wait until socket communication with QEMU has been performed. That way we're sure the pid file already exists. I think the tests can now fail due to the race condition. Stefan