summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjandob2016-03-22 14:53:06 +0100
committerjandob2016-03-22 14:53:06 +0100
commit4226f140f76f513431780be24db71adc0df3de39 (patch)
tree8b22b07b2c5122c036d33aa68d15b4fd3828df78
parentfix (diff)
downloadsystemd-init-4226f140f76f513431780be24db71adc0df3de39.tar.gz
systemd-init-4226f140f76f513431780be24db71adc0df3de39.tar.xz
systemd-init-4226f140f76f513431780be24db71adc0df3de39.zip
add timeout parameter to find_block_device
-rw-r--r--builder/dnbd3-rootfs/scripts/tools.sh49
1 files changed, 31 insertions, 18 deletions
diff --git a/builder/dnbd3-rootfs/scripts/tools.sh b/builder/dnbd3-rootfs/scripts/tools.sh
index 4831ce42..bace775e 100644
--- a/builder/dnbd3-rootfs/scripts/tools.sh
+++ b/builder/dnbd3-rootfs/scripts/tools.sh
@@ -29,28 +29,38 @@ blkid() {
echo "boot_partition"
echo "192d8b9e"
}
+sleep() {
+ ((_test_sleep_time++))
+}
'
tools_find_block_device() {
# shellcheck disable=SC2034,SC2016
local __doc__='
- >>> tools_find_block_device "boot_partition"
+ >>> tools.find_block_device "boot_partition"
/dev/sdb1
- >>> tools_find_block_device "boot_partition" /dev/sda
+ >>> tools.find_block_device "boot_partition" /dev/sda
/dev/sda2
- >>> tools_find_block_device "discoverable by blkid"
+ >>> tools.find_block_device "discoverable by blkid"
/dev/sda2
- >>> tools_find_block_device "_partition"
+ >>> tools.find_block_device "_partition"
/dev/sdb1 /dev/sdb2
- >>> tools_find_block_device "not matching anything" || echo not found
- not found
- >>> tools_find_block_device "" || echo not found
- not found
+ >>> tools.find_block_device "not matching anything"; echo $?
+ 1
+ >>> tools.find_block_device ""; echo $?
+ 1
+
+ >>> local _test_sleep_time=0
+ >>> tools.find_block_device "not matching anything" /dev/sda 10; echo $?
+ >>> echo $_test_sleep_time
+ 1
+ 10
'
local partition_pattern="$1"
- local device="$2"
-
[ "$partition_pattern" = '' ] && return 1
+ local device="$2"
+ local timeout=0
+ [ ! -z "$3" ] && timeout="$3"
tools_find_block_device_simple() {
local device_info
lsblk --noheadings --list --paths --output \
@@ -75,14 +85,17 @@ tools_find_block_device() {
done
done
}
- local candidates
- candidates=($(tools_find_block_device_simple))
- [ ${#candidates[@]} -eq 0 ] && candidates=($(tools_find_block_device_deep))
- unset -f tools_find_block_device_simple
- unset -f tools_find_block_device_deep
- [ ${#candidates[@]} -eq 0 ] && return 1
- [ ${#candidates[@]} -ne 1 ] && echo "${candidates[@]}" && return 1
- logging.plain "${candidates[0]}"
+ while ((timeout >= 0)); do
+ local candidates
+ candidates=($(tools_find_block_device_simple))
+ (( ${#candidates[@]} == 0 )) && candidates=($(tools_find_block_device_deep))
+ (( ${#candidates[@]} > 1 )) && echo "${candidates[@]}" && return 1
+ (( ${#candidates[@]} == 1 )) && echo "${candidates[0]}" && return 0
+ ((timeout == 0)) || sleep 1
+ ((timeout--))
+ done
+ # no candidates
+ return 1
}
alias tools.find_block_device="tools_find_block_device"