richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
594167
From a39c796e6ef6bcce655404b4aecc29603ebd4c3c Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Sun, 31 Jul 2022 00:11:59 +0900
594167
Subject: [PATCH] test: terminate session and user on cleanup
594167
594167
(cherry picked from commit fe9d58b25a8b8b1029dcdfbae89fac59fb429707)
594167
594167
Related: #2100464
594167
---
594167
 test/units/testsuite-35.sh | 13 ++++++++++++-
594167
 1 file changed, 12 insertions(+), 1 deletion(-)
594167
594167
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
594167
index d55ad6103e..b6b1639668 100755
594167
--- a/test/units/testsuite-35.sh
594167
+++ b/test/units/testsuite-35.sh
594167
@@ -221,7 +221,7 @@ test_shutdown() {
594167
 cleanup_session() (
594167
     set +ex
594167
 
594167
-    local uid
594167
+    local uid s
594167
 
594167
     uid=$(id -u logind-test-user)
594167
 
594167
@@ -229,6 +229,17 @@ cleanup_session() (
594167
 
594167
     systemctl stop getty@tty2.service
594167
 
594167
+    for s in $(loginctl --no-legend list-sessions | awk '$3 == "logind-test-user" { print $1 }'); do
594167
+        echo "INFO: stopping session $s"
594167
+        loginctl terminate-session "$s"
594167
+    done
594167
+
594167
+    loginctl terminate-user logind-test-user
594167
+
594167
+    if ! timeout 30 bash -c "while loginctl --no-legend | grep -q logind-test-user; do sleep 1; done"; then
594167
+        echo "WARNING: session for logind-test-user still active, ignoring."
594167
+    fi
594167
+
594167
     pkill -u "$uid"
594167
     sleep 1
594167
     pkill -KILL -u "$uid"