]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: backup /etc/udev/udev.conf only if it exists 30387/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 8 Dec 2023 17:38:41 +0000 (18:38 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 8 Dec 2023 17:38:41 +0000 (18:38 +0100)
On Fedora systemd recently moved all of its configuration files to
/usr/lib/ [0], so make sure we account for this case as well.

[   42.450325] testsuite-17.sh[800]: + mkdir -p /run/udev/rules.d
[   42.466504] testsuite-17.sh[800]: + cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bckp
[   42.503348] testsuite-17.sh[802]: cp: cannot stat '/etc/udev/udev.conf': No such file or directory

[0] https://src.fedoraproject.org/rpms/systemd/c/29eb35530b29232eed65718d0cd96d67cd7ffd6b?branch=rawhide

test/units/testsuite-17.03.sh

index fafe9d186cf2f7b8ea38883454656c5154a59deb..9af706fae165664a926b7d0227be320f946a68c6 100755 (executable)
@@ -2,17 +2,18 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -ex
 
-test_rule="/run/udev/rules.d/49-test.rules"
+TEST_RULE="/run/udev/rules.d/49-test.rules"
 KILL_PID=
 
 setup() {
-    mkdir -p "${test_rule%/*}"
-    cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bckp
-    cat >"${test_rule}" <<EOF
+    mkdir -p "${TEST_RULE%/*}"
+    [[ -e /etc/udev/udev.conf ]] && cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bak
+
+    cat >"${TEST_RULE}" <<EOF
 ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug"
 ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60"
 EOF
-    cat >>/etc/udev/udev.conf <<EOF
+    cat >/etc/udev/udev.conf <<EOF
 event_timeout=10
 timeout_signal=SIGABRT
 EOF
@@ -29,9 +30,8 @@ teardown() {
     fi
 
     rm -rf "$TMPDIR"
-
-    mv -f /etc/udev/udev.conf.bckp /etc/udev/udev.conf
-    rm -f "$test_rule"
+    rm -f "$TEST_RULE"
+    [[ -e /etc/udev/udev.conf.bak ]] && mv -f /etc/udev/udev.conf.bak /etc/udev/udev.conf
     systemctl restart systemd-udevd.service
 }