Commit d020b236 authored by Daniel Xu's avatar Daniel Xu Committed by Daniel Borkmann

selftests/bpf: Fix vmtest.sh -h to not require root

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: default avatarDaniel Xu <dxu@dxuuu.xyz>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarDaniel Müller <deso@posteo.net>
Link: https://lore.kernel.org/bpf/6a802aa37758e5a7e6aa5de294634f5518005e2b.1660064925.git.dxu@dxuuu.xyz
parent a00ed843
...@@ -307,6 +307,20 @@ update_kconfig() ...@@ -307,6 +307,20 @@ update_kconfig()
fi 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() main()
{ {
local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
...@@ -353,6 +367,8 @@ main() ...@@ -353,6 +367,8 @@ main()
done done
shift $((OPTIND -1)) shift $((OPTIND -1))
trap 'catch "$?"' EXIT
if [[ $# -eq 0 && "${debug_shell}" == "no" ]]; then if [[ $# -eq 0 && "${debug_shell}" == "no" ]]; then
echo "No command specified, will run ${DEFAULT_COMMAND} in the vm" echo "No command specified, will run ${DEFAULT_COMMAND} in the vm"
else else
...@@ -409,20 +425,4 @@ main() ...@@ -409,20 +425,4 @@ main()
fi 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 "$@" main "$@"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment