From patchwork Tue Aug 9 17:11:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 12939789 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0476FC3F6B0 for ; Tue, 9 Aug 2022 17:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245256AbiHIROL (ORCPT ); Tue, 9 Aug 2022 13:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245248AbiHIROK (ORCPT ); Tue, 9 Aug 2022 13:14:10 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE1624F0A; Tue, 9 Aug 2022 10:14:09 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C9D11320095A; Tue, 9 Aug 2022 13:14:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 09 Aug 2022 13:14:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1660065248; x=1660151648; bh=Y2 vLDOx8dQXCiR8IQJdil5G4h9Cpiut6CvYWI0fO7c4=; b=CPcQx8KuEH/7ORSc9F VlN+rsReujPhWo+E5a1UNOXDKsK6yi+eX6pDRCte0kmSYYdkg8ycCRm67HAPnf05 JztK9MXM9gj485zI8Ocs+H9dyUR3UQ2gIeMbaJC2b+F8gYW6o0rtfa2oq95WgLxO k8Pi7cWB0gYm9hxlB+cEfHs3ZaP5Joprd5qsYMxzFNDuyBNiCGb9lBYt3qZYZOVm z33j93pin1O4SRxSZ3rmITjZr6pNXojmGlRP98cOT0WgooNgP3zzMTxG8dURFF4N uDfzx8Oa85/v+H7YfBgvFh6GyTBYb7DrstEr9KZEwkoO0KoHG6db05bgpfrJLyhp z99Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660065248; x=1660151648; bh=Y2vLDOx8dQXCi R8IQJdil5G4h9Cpiut6CvYWI0fO7c4=; b=EkLqdOVNpjHMNNj31Oi1MAYmTO1dp j0UeWmT6msf3ounleDyMLwz51wyKQKrn2+5+LgPxCCh9fMwE0Hvbcmlro2kH6Isf Hc38e3TsUIx/jBB6KPoGVUlAInBeFjrx3x0vWEXtbtht0fyTY+LrLd3QmmtXPfbv BEOMEOOpoXcq1SKpqM1Qy5NEm4SI7GmTf9+oYnrY/E9qM3FgtITvu7GiQH5tbbP/ KK4ayMo7V+H8AdfcTMHHXNiI5S04dKLm6KSf6fHAxWnPsQQ9O7NYdNeE4alro6Eb O7HYwHewBtOS1iw6rEZ9E6cD7jJINkGjRc63bFSpsOnBjHeJRtAV46heA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegtddgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduie ekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Aug 2022 13:14:06 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@kernel.org Cc: Daniel Xu , linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/2] selftests/bpf: Fix vmtest.sh -h to not require root Date: Tue, 9 Aug 2022 11:11:09 -0600 Message-Id: <6a802aa37758e5a7e6aa5de294634f5518005e2b.1660064925.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Set the exit trap only after argument parsing is done. This way argument parse failure or `-h` will not require sudo. Reasoning is that it's confusing that a help message would require root access. Signed-off-by: Daniel Xu Acked-by: Daniel Müller --- tools/testing/selftests/bpf/vmtest.sh | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh index b86ae4a2e5c5..976ef7585b33 100755 --- a/tools/testing/selftests/bpf/vmtest.sh +++ b/tools/testing/selftests/bpf/vmtest.sh @@ -307,6 +307,20 @@ update_kconfig() fi } +catch() +{ + local exit_code=$1 + local exit_status_file="${OUTPUT_DIR}/${EXIT_STATUS_FILE}" + # This is just a cleanup and the directory may + # have already been unmounted. So, don't let this + # clobber the error code we intend to return. + unmount_image || true + if [[ -f "${exit_status_file}" ]]; then + exit_code="$(cat ${exit_status_file})" + fi + exit ${exit_code} +} + main() { local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" @@ -353,6 +367,8 @@ main() done shift $((OPTIND -1)) + trap 'catch "$?"' EXIT + if [[ $# -eq 0 && "${debug_shell}" == "no" ]]; then echo "No command specified, will run ${DEFAULT_COMMAND} in the vm" else @@ -409,20 +425,4 @@ main() fi } -catch() -{ - local exit_code=$1 - local exit_status_file="${OUTPUT_DIR}/${EXIT_STATUS_FILE}" - # This is just a cleanup and the directory may - # have already been unmounted. So, don't let this - # clobber the error code we intend to return. - unmount_image || true - if [[ -f "${exit_status_file}" ]]; then - exit_code="$(cat ${exit_status_file})" - fi - exit ${exit_code} -} - -trap 'catch "$?"' EXIT - main "$@" From patchwork Tue Aug 9 17:11:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 12939790 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DCF7C19F2D for ; Tue, 9 Aug 2022 17:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245231AbiHIROP (ORCPT ); Tue, 9 Aug 2022 13:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245266AbiHIROO (ORCPT ); Tue, 9 Aug 2022 13:14:14 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A1724F18; Tue, 9 Aug 2022 10:14:13 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id E7AF432007E8; Tue, 9 Aug 2022 13:14:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 09 Aug 2022 13:14:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1660065251; x=1660151651; bh=J4 gpiV71j0xKQ3FtJFMd2wIZaka/D1TIWpUk5i2bNWw=; b=jESG/Hpr8Q121hxrB7 3p8jpraFEzmRUnx2scQOkcwk3Hp0JYaxPri4/XMj87PA6yEk8ULRV0T4uOVy7/NP SZNPo4+ah1TQDk9k1+P3OFfi0GDbWYzZmghufnz/LSQQERvNY79QAoOUR+4N3xqJ 5NXDgbyID59kBDlTQqi4uK2zoRtdiwQaFDQ8k0tjyxejjBYGCj0Q07K8hytZpl6Q tAiOtO9T44q0KCyFK5jygSzMhVHeDz7CEhEhxW8pv9LcK4uVtpkSHl6KfY8m0J0j ixKlPKP3nWYQd7Va7i+MJRpCALwnE2dODHbkH5B8dRTolYV5Rtqt0+zHC4Kf6WWO qaEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660065251; x=1660151651; bh=J4gpiV71j0xKQ 3FtJFMd2wIZaka/D1TIWpUk5i2bNWw=; b=FThzYY0uIS5SIPv8vCNy7LkRFdpGH ASVbigxf79HR/4oAFlHi69N9DNwRbDJCddqG+vhslB5l14f5jxiuNNeZMnZt/87n yb2iLjdKgG+ThhIQGj/ni7ZQbb99QvKHqSKxGrzvilyj7echnAFQQ0xP4LDMl9zS pXdraZbyBPAiwNM4fIx5hXEw8Zv8vFJkqBirUEXeEcPONp8Cen7OommedeAFqAnk E4iTZ+tsxov0uNnwQX3n3NSgm3qthsSbapFxQ9FtRAXgDJGTDa+w8UHG/DCi1MHz O4QclSCbQq+T1Opdg5hXrVYaLmVE/29fIgJdJAzWZGjZ/6bZbiF1DqVdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegtddgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduie ekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Aug 2022 13:14:09 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@kernel.org Cc: Daniel Xu , linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] selftests/bpf: Fix vmtest.sh getopts optstring Date: Tue, 9 Aug 2022 11:11:10 -0600 Message-Id: <0f93b56198328b6b4da7b4cf4662d05c3edb5fd2.1660064925.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, you could see the following errors: ``` $ ./vmtest.sh -j ./vmtest.sh: option requires an argument -- j ./vmtest.sh: line 357: OPTARG: unbound variable $ ./vmtest.sh -z ./vmtest.sh: illegal option -- z ./vmtest.sh: line 357: OPTARG: unbound variable ``` Fix by adding ':' as first character of optstring. Reason is that getopts requires ':' as the first character for OPTARG to be set in the `?` and `:` error cases. Signed-off-by: Daniel Xu Acked-by: Daniel Müller --- tools/testing/selftests/bpf/vmtest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh index 976ef7585b33..a29aa05ebb3e 100755 --- a/tools/testing/selftests/bpf/vmtest.sh +++ b/tools/testing/selftests/bpf/vmtest.sh @@ -333,7 +333,7 @@ main() local exit_command="poweroff -f" local debug_shell="no" - while getopts 'hskid:j:' opt; do + while getopts ':hskid:j:' opt; do case ${opt} in i) update_image="yes"