]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: support a non-default SysV directory
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 13 Jan 2023 19:10:42 +0000 (20:10 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 14 Jan 2023 00:50:43 +0000 (09:50 +0900)
Since the directory is configurable via -Dsysvinit-path= during build,
it makes the test fail on Fedora/RHEL/CentOS, where it's set to
/etc/rc.d/init.d, instead of the default /etc/init.d. Since we can't get
the value at runtime (in a reasonable manner), let's just support the
two most common paths for now.

Follow up to 7fcf0fab078ed92a4f6c3c3658c0a9dfd67c9601.

test/units/testsuite-26.sh

index a89d089e12f121036df49b509ecd06bf08f90aff..ed45c80e11c55741e2f0346588d1b982109c8305 100755 (executable)
@@ -317,9 +317,12 @@ systemctl unset-environment IMPORT_THIS IMPORT_THIS_TOO
 
 # test for sysv-generator (issue #24990)
 if [[ -x /usr/lib/systemd/system-generators/systemd-sysv-generator ]]; then
-    mkdir -p /etc/init.d
+    # This is configurable via -Dsysvinit-path=, but we can't get the value
+    # at runtime, so let's just support the two most common paths for now.
+    [[ -d /etc/rc.d/init.d ]] && SYSVINIT_PATH="/etc/rc.d/init.d" || SYSVINIT_PATH="/etc/init.d"
+
     # invalid dependency
-    cat >/etc/init.d/issue-24990 <<\EOF
+    cat >"${SYSVINIT_PATH:?}/issue-24990" <<\EOF
 #!/bin/bash
 
 ### BEGIN INIT INFO
@@ -345,21 +348,21 @@ case "$1" in
 esac
 EOF
 
-    chmod +x /etc/init.d/issue-24990
+    chmod +x "$SYSVINIT_PATH/issue-24990"
     systemctl daemon-reload
     [[ -L /run/systemd/generator.late/test1.service ]]
     [[ -L /run/systemd/generator.late/test2.service ]]
     assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
     assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
     output=$(systemctl cat issue-24990)
-    assert_in "SourcePath=/etc/init.d/issue-24990" "$output"
+    assert_in "SourcePath=$SYSVINIT_PATH/issue-24990" "$output"
     assert_in "Description=LSB: Test" "$output"
     assert_in "After=test1.service" "$output"
     assert_in "After=remote-fs.target" "$output"
     assert_in "After=network-online.target" "$output"
     assert_in "Wants=network-online.target" "$output"
-    assert_in "ExecStart=/etc/init.d/issue-24990 start" "$output"
-    assert_in "ExecStop=/etc/init.d/issue-24990 stop" "$output"
+    assert_in "ExecStart=$SYSVINIT_PATH/issue-24990 start" "$output"
+    assert_in "ExecStop=$SYSVINIT_PATH/issue-24990 stop" "$output"
     systemctl status issue-24990 || :
     systemctl show issue-24990
     assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"
@@ -373,7 +376,7 @@ EOF
     systemctl stop issue-24990
 
     # valid dependency
-    cat >/etc/init.d/issue-24990 <<\EOF
+    cat >"$SYSVINIT_PATH/issue-24990" <<\EOF
 #!/bin/bash
 
 ### BEGIN INIT INFO
@@ -399,18 +402,18 @@ case "$1" in
 esac
 EOF
 
-    chmod +x /etc/init.d/issue-24990
+    chmod +x "$SYSVINIT_PATH/issue-24990"
     systemctl daemon-reload
     [[ -L /run/systemd/generator.late/test1.service ]]
     [[ -L /run/systemd/generator.late/test2.service ]]
     assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
     assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
     output=$(systemctl cat issue-24990)
-    assert_in "SourcePath=/etc/init.d/issue-24990" "$output"
+    assert_in "SourcePath=$SYSVINIT_PATH/issue-24990" "$output"
     assert_in "Description=LSB: Test" "$output"
     assert_in "After=remote-fs.target" "$output"
-    assert_in "ExecStart=/etc/init.d/issue-24990 start" "$output"
-    assert_in "ExecStop=/etc/init.d/issue-24990 stop" "$output"
+    assert_in "ExecStart=$SYSVINIT_PATH/issue-24990 start" "$output"
+    assert_in "ExecStop=$SYSVINIT_PATH/issue-24990 stop" "$output"
     systemctl status issue-24990 || :
     systemctl show issue-24990
     assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"