From patchwork Thu Dec 20 17:14:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 207687 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C78DA2C0090 for ; Fri, 21 Dec 2012 04:15:12 +1100 (EST) Received: from localhost ([::1]:54411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TljiA-0007PD-Os for incoming@patchwork.ozlabs.org; Thu, 20 Dec 2012 12:15:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tljhu-0007Nl-Bb for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:14:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tljhr-00086H-LN for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:14:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tljhr-000861-Dx for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:14:51 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBKHEoo5013965 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Dec 2012 12:14:50 -0500 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBKHEnJ4028677; Thu, 20 Dec 2012 12:14:49 -0500 Date: Thu, 20 Dec 2012 12:14:49 -0500 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: <79b736d734e91b6c5b675b061fe9847e8bd24065.1356022464.git.jbaron@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, blauwirbel@gmail.com, andreas.faerber@web.de, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 1/3] qtest: Enable creation of multiple qemu instances 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 From: Jason Baron Currently, the qtest harness can only spawn 1 qemu instance at a time because the parent pid is used to create the socket files. Use 'mkdtemp()' in combination with the parent pid to avoid conflicts. Signed-off-by: Jason Baron --- tests/libqtest.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 71b84c1..57665c9 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -41,6 +41,7 @@ struct QTestState GString *rx; gchar *pid_file; char *socket_path, *qmp_socket_path; + char *tmp_dir; }; #define g_assert_no_errno(ret) do { \ @@ -105,7 +106,6 @@ QTestState *qtest_init(const char *extra_args) { QTestState *s; int sock, qmpsock, ret, i; - gchar *pid_file; gchar *command; const char *qemu_binary; pid_t pid; @@ -115,9 +115,11 @@ QTestState *qtest_init(const char *extra_args) s = g_malloc(sizeof(*s)); - s->socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid()); - s->qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid()); - pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid()); + s->tmp_dir = g_strdup_printf("/tmp/qtest-%d-XXXXXX", getpid()); + g_assert(mkdtemp(s->tmp_dir) != NULL); + s->socket_path = g_strdup_printf("%s/%s", s->tmp_dir, "sock"); + s->qmp_socket_path = g_strdup_printf("%s/%s", s->tmp_dir, "qmp"); + s->pid_file = g_strdup_printf("%s/%s", s->tmp_dir, "pid"); sock = init_socket(s->socket_path); qmpsock = init_socket(s->qmp_socket_path); @@ -131,7 +133,7 @@ QTestState *qtest_init(const char *extra_args) "-pidfile %s " "-machine accel=qtest " "%s", qemu_binary, s->socket_path, - s->qmp_socket_path, pid_file, + s->qmp_socket_path, s->pid_file, extra_args ?: ""); ret = system(command); @@ -143,7 +145,6 @@ QTestState *qtest_init(const char *extra_args) s->qmp_fd = socket_accept(qmpsock); s->rx = g_string_new(""); - s->pid_file = pid_file; for (i = 0; i < MAX_IRQ; i++) { s->irq_level[i] = false; } @@ -172,9 +173,11 @@ void qtest_quit(QTestState *s) unlink(s->pid_file); unlink(s->socket_path); unlink(s->qmp_socket_path); + unlink(s->tmp_dir); g_free(s->pid_file); g_free(s->socket_path); g_free(s->qmp_socket_path); + g_free(s->tmp_dir); } static void socket_sendf(int fd, const char *fmt, va_list ap)