From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US7Il-0003kP-6o for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:56:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1US7Ii-0002lf-RH for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:56:07 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:52706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US78W-0006hO-J6 for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:45:33 -0400 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 17 Apr 2013 00:43:15 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id EE91F2BB0023 for ; Wed, 17 Apr 2013 00:45:26 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3GEW12S8192442 for ; Wed, 17 Apr 2013 00:32:01 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r3GEjQ9x001473 for ; Wed, 17 Apr 2013 00:45:26 +1000 From: Anthony Liguori Date: Tue, 16 Apr 2013 09:45:15 -0500 Message-Id: <1366123521-4330-2-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1366123521-4330-1-git-send-email-aliguori@us.ibm.com> References: <1366123521-4330-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH 1/7] qtest: don't use system command to avoid double fork List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori Currently we waitpid on the child process we spawn off that does nothing more than system() another process. While this does not appear to be incorrect, it's wasteful and confusing so get rid of it. Signed-off-by: Anthony Liguori --- tests/libqtest.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 389596a..884f959 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -107,7 +107,7 @@ static pid_t qtest_qemu_pid(QTestState *s) QTestState *qtest_init(const char *extra_args) { QTestState *s; - int sock, qmpsock, ret, i; + int sock, qmpsock, i; gchar *pid_file; gchar *command; const char *qemu_binary; @@ -136,10 +136,8 @@ QTestState *qtest_init(const char *extra_args) "%s", qemu_binary, s->socket_path, s->qmp_socket_path, pid_file, extra_args ?: ""); - - ret = system(command); - exit(ret); - g_free(command); + execlp("/bin/sh", "sh", "-c", command, NULL); + exit(1); } s->fd = socket_accept(sock); @@ -169,9 +167,8 @@ void qtest_quit(QTestState *s) pid_t pid = qtest_qemu_pid(s); if (pid != -1) { - /* kill QEMU, but wait for the child created by us to run system() */ kill(pid, SIGTERM); - waitpid(s->child_pid, &status, 0); + waitpid(pid, &status, 0); } unlink(s->pid_file); -- 1.8.0