From patchwork Wed Jun 28 20:08:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9815317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F93560365 for ; Wed, 28 Jun 2017 20:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02DB4284EA for ; Wed, 28 Jun 2017 20:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBD0328517; Wed, 28 Jun 2017 20:09:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 908B5284EA for ; Wed, 28 Jun 2017 20:09:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751870AbdF1UJZ (ORCPT ); Wed, 28 Jun 2017 16:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40466 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787AbdF1UJY (ORCPT ); Wed, 28 Jun 2017 16:09:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 969D0C049D5D for ; Wed, 28 Jun 2017 20:09:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 969D0C049D5D Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=rkrcmar@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 969D0C049D5D Received: from potion (unknown [10.43.2.65]) by smtp.corp.redhat.com (Postfix) with SMTP id 0359C18257; Wed, 28 Jun 2017 20:09:20 +0000 (UTC) Received: by potion (sSMTP sendmail emulation); Wed, 28 Jun 2017 22:09:20 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Cc: Paolo Bonzini , Drew Jones , Laurent Vivier , Thomas Huth , David Hildenbrand Subject: [kvm-unit-tests PATCH 4/5] scripts/arch-run: fix qemu binary search failure path Date: Wed, 28 Jun 2017 22:08:56 +0200 Message-Id: <20170628200857.1718-5-rkrcmar@redhat.com> In-Reply-To: <20170628200857.1718-1-rkrcmar@redhat.com> References: <20170628200857.1718-1-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Jun 2017 20:09:23 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Doing exit from a subshell won't exit the main shell, so arch-run will try to continue without a working QEMU if search_qemu_binary() failed. Also fix error message from search_qemu_binary(). Signed-off-by: Radim Krčmář --- I was thinking about using `set -e` instead, so the "return 2" from search_qemu_binary() would stop the script without the explicit exit. It required just four changes to make the script work (resulting in better diffstat), but would likely complicate future development. The second alternative would be to call just "search_qemu_binary" and set the qemu variable from it. This would allow "exit 2" from search_qemu_binary() to also exit arch/run, but side-effects on variables seem worse than the first alternative ... --- arm/run | 3 ++- powerpc/run | 3 ++- s390x/run | 3 ++- scripts/arch-run.bash | 6 +++--- x86/run | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arm/run b/arm/run index 8d8918a461dc..d7d778fe1645 100755 --- a/arm/run +++ b/arm/run @@ -31,7 +31,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! $qemu -machine '?' 2>&1 | grep 'ARM Virtual Machine' > /dev/null; then echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." diff --git a/powerpc/run b/powerpc/run index 3f69386c642a..e43c9fd8063c 100755 --- a/powerpc/run +++ b/powerpc/run @@ -28,7 +28,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then echo "$qemu doesn't support pSeries ('-machine pseries'). Exiting." diff --git a/s390x/run b/s390x/run index 6df348a93783..ce8d45c2c8fd 100755 --- a/s390x/run +++ b/s390x/run @@ -28,7 +28,8 @@ if [ -z "$ACCEL" ]; then fi fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 M='-machine s390-ccw-virtio' M+=",accel=$ACCEL" diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 6e429a8748f4..994c1aa9c0cd 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -176,9 +176,9 @@ search_qemu_binary () done if [ -z "$qemu" ]; then - echo "A QEMU binary was not found." - echo "You can set a custom location by using the QEMU= environment variable." - exit 2 + echo "A QEMU binary was not found." >&2 + echo "You can set a custom location by using the QEMU= environment variable." >&2 + return 2 fi command -v $qemu export PATH=$save_path diff --git a/x86/run b/x86/run index a06a7c0f80c8..1099c5ccd609 100755 --- a/x86/run +++ b/x86/run @@ -9,7 +9,8 @@ if [ -z "$STANDALONE" ]; then source scripts/arch-run.bash fi -qemu=$(search_qemu_binary) +qemu=$(search_qemu_binary) || + exit 2 if ! ${qemu} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null; then