All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com
Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz,
	stefanb@linux.ibm.com, Roberto Sassu <roberto.sassu@huawei.com>
Subject: [PATCH ima-evm-utils v3 04/11] Pass cleanup function and its arguments to _report_exit_and_cleanup()
Date: Wed, 25 Jan 2023 09:50:23 +0100	[thread overview]
Message-ID: <20230125085030.1568256-5-roberto.sassu@huaweicloud.com> (raw)
In-Reply-To: <20230125085030.1568256-1-roberto.sassu@huaweicloud.com>

From: Roberto Sassu <roberto.sassu@huawei.com>

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>
---
 tests/boot_aggregate.test |  2 +-
 tests/fsverity.test       |  3 +--
 tests/functions.sh        | 10 ++++++++--
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/boot_aggregate.test b/tests/boot_aggregate.test
index d7115660385f..ca5faf9cd97d 100755
--- a/tests/boot_aggregate.test
+++ b/tests/boot_aggregate.test
@@ -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}"
diff --git a/tests/fsverity.test b/tests/fsverity.test
index 549c42a32608..be9594010de5 100755
--- a/tests/fsverity.test
+++ b/tests/fsverity.test
@@ -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
diff --git a/tests/functions.sh b/tests/functions.sh
index 8f6f02dfcd95..cf83ad21562f 100755
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -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
 }
 
@@ -312,4 +318,4 @@ _softhsm_teardown() {
   rm -rf "${SOFTHSM_SETUP_CONFIGDIR}"
   unset SOFTHSM_SETUP_CONFIGDIR SOFTHSM2_CONF PKCS11_KEYURI \
     EVMCTL_ENGINE OPENSSL_ENGINE OPENSSL_KEYFORM
-}
\ No newline at end of file
+}
-- 
2.25.1


  parent reply	other threads:[~2023-01-25  8:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25  8:50 [PATCH ima-evm-utils v3 00/11] Support testing in new enviroments Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 01/11] Fix error messages and vars in calc_evm_hmac() Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 02/11] Add config for UML kernel Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 03/11] Compile the UML kernel and download it in Github Actions Roberto Sassu
2023-01-25 19:17   ` Mimi Zohar
2023-01-26  9:09     ` Roberto Sassu
2023-01-25  8:50 ` Roberto Sassu [this message]
2023-01-25 13:52   ` [PATCH ima-evm-utils v3 04/11] Pass cleanup function and its arguments to _report_exit_and_cleanup() Stefan Berger
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 05/11] Add support for creating a new testing environment in functions.sh Roberto Sassu
2023-01-25 13:36   ` Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 06/11] Introduce TST_LIST variable to select a test to execute Roberto Sassu
2023-01-25 14:06   ` Stefan Berger
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 07/11] Add tests for EVM portable signatures Roberto Sassu
2023-01-25 23:15   ` Stefan Berger
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 08/11] Adapt fsverity.test to be able to run in a new testing environment Roberto Sassu
2023-01-25 22:45   ` Stefan Berger
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 09/11] Use in-place built fsverity binary instead of installing it Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 10/11] ci: haveged requires EPEL on CentOS stream:8 Roberto Sassu
2023-01-25  8:50 ` [PATCH ima-evm-utils v3 11/11] Temporarily remove CONFIG_DEBUG_SG to test portable signatures Roberto Sassu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230125085030.1568256-5-roberto.sassu@huaweicloud.com \
    --to=roberto.sassu@huaweicloud.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=pvorel@suse.cz \
    --cc=roberto.sassu@huawei.com \
    --cc=stefanb@linux.ibm.com \
    --cc=vt@altlinux.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.