From 35177dbef0ae8e9b1ea67bcb72f71f9a7b4b9934 Mon Sep 17 00:00:00 2001 From: dann frazier Date: Mon, 26 Oct 2020 17:25:18 -0600 Subject: [PATCH] Add time_elapsed() function, subsuming $local_top_time Generalize the elapsed time tracking in local-top so that it can be used elsewhere. This requires some additional quoting in local_device_setup() comparisons to pass shellcheck. Now that the reference time is recorded earlier (in init vs. local-top), the rootdev wait time will now be reduced by however long it it takes to process init-premount. The belief is that our wait time is sufficiently long for that to be negligible. Also, this could potentially break any local-top scripts that use $local_top_time directly. A survey of the current packages in sid shows no packages that contain a file under /usr/share/initramfs-tools/scripts/local-top/ that contain "local_top_time". Signed-off-by: dann frazier --- init | 5 +++++ scripts/functions | 19 +++++++++++++++++++ scripts/local | 17 +++-------------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/init b/init index 3ad5579..70a6b22 100755 --- a/init +++ b/init @@ -218,6 +218,10 @@ maybe_break modules load_modules [ "$quiet" != "y" ] && log_end_msg +starttime="$(_uptime)" +starttime=$((starttime + 1)) # round up +export starttime + if [ "$ROOTDELAY" ]; then sleep "$ROOTDELAY" fi @@ -310,6 +314,7 @@ unset noresume unset fastboot unset forcefsck unset fsckfix +unset starttime # Move virtual filesystems over to the real filesystem mount -n -o move /sys ${rootmnt}/sys diff --git a/scripts/functions b/scripts/functions index eccad66..2cc2f9a 100644 --- a/scripts/functions +++ b/scripts/functions @@ -144,6 +144,25 @@ load_modules() fi } +_uptime() { + local uptime + uptime="$(cat /proc/uptime)" + uptime="${uptime%%[. ]*}" + echo "$uptime" +} + +time_elapsed() { + # shellcheck disable=SC2154 + if [ -z "$starttime" ]; then + log_failure_msg "time_elapsed() called before \$starttime initialized" + echo 0 + fi + local delta + delta="$(_uptime)" + delta=$((delta - starttime)) + echo "$delta" +} + # lilo compatibility parse_numeric() { case $1 in diff --git a/scripts/local b/scripts/local index a103e68..becb798 100644 --- a/scripts/local +++ b/scripts/local @@ -8,14 +8,6 @@ local_top() [ "$quiet" != "y" ] && log_end_msg fi local_top_used=yes - - # Start time for measuring elapsed time in local_device_setup - if [ -z "${local_top_time}" ]; then - local_top_time="$(cat /proc/uptime)" - local_top_time="${local_top_time%%[. ]*}" - local_top_time=$((local_top_time + 1)) # round up - export local_top_time - fi } local_block() @@ -44,7 +36,6 @@ local_bottom() fi local_premount_used=no local_top_used=no - unset local_top_time } # $1=device ID to mount @@ -94,9 +85,7 @@ local_device_setup() while true; do sleep 1 - time_elapsed="$(cat /proc/uptime)" - time_elapsed="${time_elapsed%%[. ]*}" - time_elapsed=$((time_elapsed - local_top_time)) + time_elapsed="$(time_elapsed)" local_block "${dev_id}" @@ -113,7 +102,7 @@ local_device_setup() else break fi - if [ ${count} -ge ${time_elapsed} ]; then + if [ "${count}" -ge "${time_elapsed}" ]; then break; fi /scripts/local-block/mdadm "${dev_id}" @@ -125,7 +114,7 @@ local_device_setup() log_end_msg 0 break fi - if [ ${time_elapsed} -ge "${slumber}" ]; then + if [ "${time_elapsed}" -ge "${slumber}" ]; then log_end_msg 1 || true break fi