Skip to content

Commit 31f8b82

Browse files
qmonnetAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests, bpftool: Set EXIT trap after usage function
The trap on EXIT is used to clean up any temporary directory left by the build attempts. It is not needed when the user simply calls the script with its --help option, and may not be needed either if we add checks (e.g. on the availability of bpftool files) before the build attempts. Let's move this trap and related variables lower down in the code, so that we don't accidentally change the value returned from the script on early exits at pre-checks. Signed-off-by: Quentin Monnet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a89b2cb commit 31f8b82

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

tools/testing/selftests/bpf/test_bpftool_build.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
33

4-
ERROR=0
5-
TMPDIR=
6-
7-
# If one build fails, continue but return non-0 on exit.
8-
return_value() {
9-
if [ -d "$TMPDIR" ] ; then
10-
rm -rf -- $TMPDIR
11-
fi
12-
exit $ERROR
13-
}
14-
trap return_value EXIT
15-
164
case $1 in
175
-h|--help)
186
echo -e "$0 [-j <n>]"
197
echo -e "\tTest the different ways of building bpftool."
208
echo -e ""
219
echo -e "\tOptions:"
2210
echo -e "\t\t-j <n>:\tPass -j flag to 'make'."
23-
exit
11+
exit 0
2412
;;
2513
esac
2614

@@ -33,6 +21,18 @@ SCRIPT_REL_DIR=$(dirname $SCRIPT_REL_PATH)
3321
KDIR_ROOT_DIR=$(realpath $PWD/$SCRIPT_REL_DIR/../../../../)
3422
cd $KDIR_ROOT_DIR
3523

24+
ERROR=0
25+
TMPDIR=
26+
27+
# If one build fails, continue but return non-0 on exit.
28+
return_value() {
29+
if [ -d "$TMPDIR" ] ; then
30+
rm -rf -- $TMPDIR
31+
fi
32+
exit $ERROR
33+
}
34+
trap return_value EXIT
35+
3636
check() {
3737
local dir=$(realpath $1)
3838

0 commit comments

Comments
 (0)