]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-64-UDEV-STORAGE: several fixlets for check_device_units()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 Jul 2025 18:35:55 +0000 (03:35 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 16:07:14 +0000 (17:07 +0100)
To suppress the following warnings in case check_device_unit() failed e.g.
when the device is already removed:
```
sed: couldn't write 130 items to stdout: Broken pipe
awk: write failure (Broken pipe)
awk: close failed on file "/dev/stdout" (Broken pipe)
```

(cherry picked from commit 453cbbe47b4e268f239f75d7c19f2ddef495bd81)

test/units/TEST-64-UDEV-STORAGE.sh

index af935326252f314e918d57d33503e4fd14db53a6..d489159eb71dd167f648db7dd700530f0c776eb7 100755 (executable)
@@ -117,7 +117,7 @@ check_device_unit() {(
         fi
     done
 
-    read -r -a links < <(udevadm info "$syspath" | sed -ne '/SYSTEMD_ALIAS=/ { s/^E: SYSTEMD_ALIAS=//; p }' 2>/dev/null)
+    read -r -a links < <(udevadm info -q property --property SYSTEMD_ALIAS --value "$syspath" 2>/dev/null)
     for link in "${links[@]}"; do
         if [[ "$link" == "$path" ]]; then # SYSTEMD_ALIAS= are absolute
             return 0
@@ -131,7 +131,7 @@ check_device_unit() {(
 check_device_units() {(
     set +x
 
-    local log_level path paths
+    local log_level path paths unit units
 
     log_level="${1?}"
     shift
@@ -143,12 +143,13 @@ check_device_units() {(
         fi
     done
 
-    while read -r unit _; do
+    read -r -a units < <(systemctl list-units --all --type=device --no-legend dev-* | awk '$1 !~ /dev-tty.+/ && $4 == "plugged" { print $1 }' | sed -e 's/\.device$//')
+    for unit in "${units[@]}"; do
         path=$(systemd-escape --path --unescape "$unit")
         if ! check_device_unit "$log_level" "$path"; then
            return 1
         fi
-    done < <(systemctl list-units --all --type=device --no-legend dev-* | awk '$1 !~ /dev-tty.+/ && $4 == "plugged" { print $1 }' | sed -e 's/\.device$//')
+    done
 
     return 0
 )}