slew: a distribution-friendly init/rc framework based on s6/s6-rc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
619 B

#!/bin/rc
priv=./data/rate
fn echo_ret {
if ([ $1 -eq 256 ]) {
echo 'killed by signal `'$2''''
} else echo 'exited with code `'$1''''
}
fn rate_run {
[ -d $priv ] || install -d -o root -g adm -m 0750 $priv
if ([ -f $priv/delay ]) sleep `{cat $priv/delay}
date +%s > $priv/date
}
fn rate_finish {
cur=`{date +%s}
prev=`{cat $priv/date}
dif=`{expr $cur - $prev || true}
if ([ $dif -ge $1 -o $2 -eq 0 -o $2 -eq 256 ]) {
rm -f $priv/delay
} else if ([ -f $priv/delay ]) {
if (delay=`{cat $priv/delay}; [ $delay -lt $1 ]) {
expr $delay '*' 2 > $priv/delay || true
}
} else echo 1 > $priv/delay
}