From 423297501b298041533a84d1d2fbbde5c220655f Mon Sep 17 00:00:00 2001 From: illiliti Date: Sat, 15 Feb 2020 22:33:13 +0300 Subject: [PATCH] fix race conditions --- init | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/init b/init index 8d56d8d..94499f2 100644 --- a/init +++ b/init @@ -64,29 +64,30 @@ setup_udev() { findfs_sh() { case "${1%%=*}" in LABEL) - printf "/dev/disk/by-label/%s\n" "${1##*=}" + device="/dev/disk/by-label/${1##*=}" ;; UUID) - printf "/dev/disk/by-uuid/%s\n" "${1##*=}" + device="/dev/disk/by-uuid/${1##*=}" ;; PARTUUID) - printf "/dev/disk/by-partuuid/%s\n" "${1##*=}" + device="/dev/disk/by-partuuid/${1##*=}" ;; /dev/*) - printf "%s\n" "$1" + device="$1" ;; *) panic "findfs option broken" ;; esac + + # avoid race condition + until [ -e "$device" ]; do sleep 0.5; done + + printf "%s\n" "$device" } # unlock LUKS container unlock_luks() { - # TODO investigate this - # avoid race condition - sleep 1.5 - # TODO improve mapper name ( crypttab or config option ) cryptsetup $luks_args luksOpen $(findfs_sh "$luks_root") luks_root || panic "failed to unlock luks container" } @@ -98,11 +99,7 @@ trigger_lvm() { # mount rootfs to /mnt/root mnt_rootfs() { - # TODO investigate this - # avoid race condition - sleep 1.5 - - mount $root_type $root_args $(findfs_sh "$root") /mnt/root || panic "failed to mount rootfs" + mount ${root_type:+-t $root_type} $root_args $(findfs_sh "$root") /mnt/root || panic "failed to mount rootfs" } # kill and unmount