From d7034574361d86a42cb472c672aa833864b27516 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 3 Nov 2023 10:08:21 +0300 Subject: [PATCH] msleep --- common/base.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/common/base.sh b/common/base.sh index 93105b3..ce7839c 100644 --- a/common/base.sh +++ b/common/base.sh @@ -197,6 +197,12 @@ fix_sbin_path() export PATH } +# it can calculate floating point expr +calc() +{ + awk "BEGIN { print $*}"; +} + fsleep_setup() { [ -n "$FSLEEP" ] || { @@ -220,25 +226,30 @@ fsleep_setup() fi } } -minsleep() +msleep() { + # $1 - milliseconds case "$FSLEEP" in 1) - sleep 0.1 + sleep $(calc $1/1000) ;; 2) - busybox usleep 100000 + busybox usleep $(calc $1*1000) ;; 3) - read -t 0.1 + read -t $(calc $1/1000) ;; 4) - ucode -e "system(['sleep','1'], 100)" + ucode -e "system(['sleep','2147483647'], $1)" ;; 5) - lua -e 'require "nixio".nanosleep(0,100000000)' + lua -e "require 'nixio'.nanosleep($(($1/1000)),$(calc $1%1000*1000000))" ;; *) sleep 1 esac } +minsleep() +{ + msleep 100 +}