From 4506edf75151f8ae91a14610628aab41f924a73e Mon Sep 17 00:00:00 2001 From: "Slawomir Wojciech Wojtczak (vermaden)" Date: Wed, 3 Apr 2013 08:09:20 +0200 Subject: [PATCH] Implement BOOTDELAY option to wait for boot process to complete. Fix devd(8) config (thanks to LARKIND) to match all needed devices and their partitions. --- automount | 32 +++++++++++++++++++++++++++++--- automount_devd.conf | 4 ++-- automount_devd_DEBUG.conf | 4 ++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/automount b/automount index 9535c2d..c8007c7 100755 --- a/automount +++ b/automount @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (c) 2012 Slawomir Wojciech Wojtczak (vermaden) +# Copyright (c) 2012-2013 Slawomir Wojciech Wojtczak (vermaden) # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -107,10 +107,16 @@ TIMEOUT (set to 8 by default) example: TIMEOUT="8" -DELAY (set to 0.3 seconds by default) +DELAY (set to 1 second by default) How often to check for device availability. example: DELAY="2.5" + +BOOTDELAY (set to 45 seconds by default) + How long to wait for boot process to complete. + + example: BOOTDELAY="30" + EOF exit 0 } @@ -143,7 +149,8 @@ fi : ${USER="0"} # which user to use for popup : ${FM="0"} # which file manager to use : ${TIMEOUT="8"} # stop waiting for device after that time -: ${DELAY="0.3"} # check for the device node that often +: ${DELAY="1"} # check for the device node that often +: ${BOOTDELAY="45"} # wait for boot process to complete if [ "${USERUMOUNT}" = YES ] then @@ -232,6 +239,25 @@ __wait_for_device() { # 1=DEV done } +__wait_for_boot() { + local BOOTTIME=$( sysctl -n kern.boottime | awk -F',' '{print $1}' | awk '{print $NF }' ) + local CURRTIME=$( date +%s ) + local UPTIME=$(( ${CURRTIME} - ${BOOTTIME} )) + while [ ${UPTIME} -lt ${BOOTDELAY} ] + do + sleep 1 + local WAIT=1 + local CURRTIME=$( date +%s ) + local UPTIME=$(( ${CURRTIME} - ${BOOTTIME} )) + done + if [ ${WAIT} -eq 1 ] + then + __log "${DEV}: wait for boot process completed after '${BOOTDELAY}' seconds" + fi +} + +__wait_for_boot + DEV=/dev/${1} case ${2} in diff --git a/automount_devd.conf b/automount_devd.conf index 2614c98..9aa349a 100644 --- a/automount_devd.conf +++ b/automount_devd.conf @@ -1,14 +1,14 @@ notify 100 { match "system" "DEVFS"; match "type" "CREATE"; - match "cdev" "(da|mmcsd)[0-9]+"; + match "cdev" "(da|mmcsd)[0-9]+.*"; action "/usr/local/sbin/automount $cdev attach"; }; notify 100 { match "system" "DEVFS"; match "type" "DESTROY"; - match "cdev" "(da|mmcsd)[0-9]+"; + match "cdev" "(da|mmcsd)[0-9]+.*"; action "/usr/local/sbin/automount $cdev detach"; }; diff --git a/automount_devd_DEBUG.conf b/automount_devd_DEBUG.conf index fd8f35a..729bebb 100644 --- a/automount_devd_DEBUG.conf +++ b/automount_devd_DEBUG.conf @@ -1,14 +1,14 @@ notify 200 { match "system" "DEVFS"; match "type" "CREATE"; - match "cdev" "(da|mmcsd)[0-9]+"; + match "cdev" "(da|mmcsd)[0-9]+.*"; action "/bin/sh -xe /usr/local/sbin/automount $cdev attach >> /root/DEBUG.$cdev.attach 2>&1"; }; notify 200 { match "system" "DEVFS"; match "type" "DESTROY"; - match "cdev" "(da|mmcsd)[0-9]+"; + match "cdev" "(da|mmcsd)[0-9]+.*"; action "/bin/sh -xe /usr/local/sbin/automount $cdev detach >> /root/DEBUG.$cdev.detach 2>&1"; };