diff mbox series

[bpf-next,1/2] selftests/bpf: Fix vmtest.sh -h to not require root

Message ID 6a802aa37758e5a7e6aa5de294634f5518005e2b.1660064925.git.dxu@dxuuu.xyz (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series bpf/selftests: Small vmtest.sh fixes | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 10 maintainers not CCed: john.fastabend@gmail.com song@kernel.org sdf@google.com martin.lau@linux.dev linux-kselftest@vger.kernel.org jolsa@kernel.org mykolal@fb.com shuah@kernel.org haoluo@google.com yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest fail Script vmtest.sh not found in tools/testing/selftests/bpf/Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 48 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 pending Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-16
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Daniel Xu Aug. 9, 2022, 5:11 p.m. UTC
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 <dxu@dxuuu.xyz>
---
 tools/testing/selftests/bpf/vmtest.sh | 32 +++++++++++++--------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Daniel Müller Aug. 9, 2022, 6:19 p.m. UTC | #1
On Tue, Aug 09, 2022 at 11:11:09AM -0600, Daniel Xu wrote:
> 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 <dxu@dxuuu.xyz>
> ---
>  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 "$@"
> -- 
> 2.37.1
> 

Makes sense and looks good to me.

Acked-by: Daniel Müller <deso@posteo.net>
diff mbox series

Patch

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 "$@"