]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: move runas() to the shared utility library 27664/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 16 May 2023 20:41:03 +0000 (22:41 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 16 May 2023 21:07:45 +0000 (23:07 +0200)
test/units/testsuite-07.main-PID-change.sh
test/units/testsuite-43.sh
test/units/testsuite-58.sh
test/units/util.sh

index da23032d1ec107261d6d2f250aa274cbc3ece23d..6d302452af885f05e642556cc881df8cabe431b1 100755 (executable)
@@ -5,6 +5,9 @@ set -o pipefail
 
 # Test changing the main PID
 
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
 systemd-analyze log-level debug
 
 # The main service PID should be the parent bash process
@@ -166,12 +169,6 @@ test "$(systemctl show -P Result test-true.scope)" = success
 
 # Test that user scope units work as well
 
-runas() {
-    declare userid=$1
-    shift
-    XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
-}
-
 systemctl start user@4711.service
 runas testuser systemd-run --scope --user --unit test-true.scope /bin/true
 test "$(systemctl show -P Result test-true.scope)" = success
index ae979d734b718ab7d6ebfffbaf85a2bc7fbdf67c..f9819f2c05636a24a5155430a4d2d1113b10588d 100755 (executable)
@@ -3,13 +3,10 @@
 set -eux
 set -o pipefail
 
-systemd-analyze log-level debug
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
 
-runas() {
-    declare userid=$1
-    shift
-    XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
-}
+systemd-analyze log-level debug
 
 runas testuser systemd-run --wait --user --unit=test-private-users \
     -p PrivateUsers=yes -P echo hello
index 86c56a24f88ff7f9a96cc20ad4445641db8d4736..ecb376476ab5eb43b682a063958195bddc2d0175 100755 (executable)
@@ -3,11 +3,8 @@
 set -eux
 set -o pipefail
 
-runas() {
-    declare userid=$1
-    shift
-    XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
-}
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
 
 if ! command -v systemd-repart &>/dev/null; then
     echo "no systemd-repart" >/skipped
index 4e214251cc69179eca2328cba734123962e403fa..d151c39965d4072c39b33de320c3452869b080b6 100755 (executable)
@@ -74,3 +74,9 @@ get_cgroup_hierarchy() {
             exit 1
     esac
 }
+
+runas() {
+    local userid="${1:?}"
+    shift
+    XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
+}