Blob Blame History Raw
From 60bc6c654dfbcbfeac0120143dd9869ceeb1a56e Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 14 Jun 2022 21:08:04 +0900
Subject: [PATCH] test: use trap RETURN

(cherry picked from commit 6243063824838e027754cc2737bb975472d62de2)

Related: #2087652
---
 test/units/testsuite-35.sh | 10 ++--------
 test/units/testsuite-45.sh | 10 ++--------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
index e369cf8701..05d2a6c4c3 100755
--- a/test/units/testsuite-35.sh
+++ b/test/units/testsuite-35.sh
@@ -91,7 +91,7 @@ test_suspend_on_lid() {
     fi
 
     KILL_PID=
-    trap test_suspend_tear_down EXIT
+    trap test_suspend_tear_down RETURN
 
     # create fake suspend
     mkdir -p /run/systemd/system/systemd-suspend.service.d
@@ -184,9 +184,6 @@ EOF
         echo "logind crashed" >&2
         exit 1
     fi
-
-    test_suspend_tear_down
-    trap - EXIT
 }
 
 test_shutdown() {
@@ -269,7 +266,7 @@ test_session() {
         return
     fi
 
-    trap test_session_tear_down EXIT
+    trap test_session_tear_down RETURN
 
     # add user
     useradd -s /bin/bash logind-test-user
@@ -361,9 +358,6 @@ EOF
         getfacl -p "$dev" >&2
         exit 1
     fi
-
-    test_session_tear_down
-    trap - EXIT
 }
 
 : >/failed
diff --git a/test/units/testsuite-45.sh b/test/units/testsuite-45.sh
index fd8a99076b..322d8086e7 100755
--- a/test/units/testsuite-45.sh
+++ b/test/units/testsuite-45.sh
@@ -23,7 +23,7 @@ test_timezone() {
         mv /etc/timezone /tmp/timezone.bak
     fi
 
-    trap restore_timezone EXIT
+    trap restore_timezone RETURN
 
     if [[ -L /etc/localtime ]]; then
         ORIG_TZ=$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')
@@ -49,9 +49,6 @@ test_timezone() {
             assert_eq "$(cat /etc/timezone)" "$ORIG_TZ"
         fi
     fi
-
-    restore_timezone
-    trap - EXIT
 }
 
 restore_adjtime() {
@@ -75,7 +72,7 @@ test_adjtime() {
         mv /etc/adjtime /etc/adjtime.bak
     fi
 
-    trap restore_adjtime EXIT
+    trap restore_adjtime RETURN
 
     echo 'no adjtime file'
     rm -f /etc/adjtime
@@ -182,9 +179,6 @@ LOCAL"
     assert_eq "$(cat /etc/adjtime)" "0.0 0 0
 0
 LOCAL"
-
-    restore_adjtime
-    trap - EXIT
 }
 
 assert_ntp() {