1
0
mirror of https://git.code.sf.net/p/linux-ima/ima-evm-utils synced 2025-04-27 22:32:31 +02:00

Pass cleanup function and its arguments to _report_exit_and_cleanup()

If an error occurs before any test is executed, _report_exit_and_cleanup()
returns 77 ($SKIP) as exit code, which might not reflect the real exit code
at the time the script terminated its execution.

If the function registered in the shell trap() is a cleanup function
calling _report_exit_and_cleanup() inside, the latter will not have access
to the exit code at the time of the trap but instead to the exit code of
the cleanup function.

To solve this issue, pass the cleanup function and its arguments to
_report_exit_and_cleanup(), so that the latter can first get the script
exit code and then can execute the cleanup function.

Finally, if no test was executed, return the exit code at the time of the
trap() instead of 77.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
Roberto Sassu 2023-01-26 14:58:00 +01:00 committed by Mimi Zohar
parent 3fadf997a6
commit 03b5d159ca
3 changed files with 10 additions and 5 deletions

View File

@ -12,7 +12,7 @@
# for verifying the calculated boot_aggregate is included in this
# directory as well.
trap cleanup SIGINT SIGTERM EXIT
trap '_report_exit_and_cleanup cleanup' SIGINT SIGTERM EXIT
# Base VERBOSE on the environment variable, if set.
VERBOSE="${VERBOSE:-0}"

View File

@ -47,7 +47,7 @@ FSVERITY="$(which fsverity)"
_require dd mkfs blkid e2fsck tune2fs evmctl setfattr
./gen-keys.sh >/dev/null 2>&1
trap cleanup SIGINT SIGTERM EXIT
trap '_report_exit_and_cleanup cleanup' SIGINT SIGTERM EXIT
cleanup() {
if [ -e $TST_MNT ]; then
@ -58,7 +58,6 @@ cleanup() {
rm "$TST_IMG"
fi
fi
_report_exit_and_cleanup
}
# Loopback mount a file

View File

@ -250,10 +250,14 @@ _enable_gost_engine() {
# Show test stats and exit into automake test system
# with proper exit code (same as ours). Do cleanups.
_report_exit_and_cleanup() {
local exit_code=$?
if [ -n "${WORKDIR}" ]; then
rm -rf "${WORKDIR}"
fi
"$@"
if [ $testsfail -gt 0 ]; then
echo "================================="
echo " Run with FAILEARLY=1 $0 $*"
@ -271,8 +275,10 @@ _report_exit_and_cleanup() {
exit "$FAIL"
elif [ $testspass -gt 0 ]; then
exit "$OK"
else
elif [ $testsskip -gt 0 ]; then
exit "$SKIP"
else
exit "$exit_code"
fi
}