others: improve cru locking to prevent concurrent updates

There are reported cases of cron jobs being lost under heavy cru
activity (concurrent executions). Protect against concurrent add
or deletes with a more robust locking mechanism using flock.

File descriptor 278 is used as it represents the letters C-R-U
on a telephone keypad.

Ref: ac1badcd0b
arm-master
pedro 2 years ago
parent 1dc55282e6
commit 118a48add5

@ -7,13 +7,8 @@ N="$F.new"
L="/var/lock/cron.lock"
if [ $# -gt 1 -a "$1" = "a" -o "$1" = "d" ]; then
I=$((($$ % 25) + 5))
while ! rm $L 2>/dev/null; do
I=$(($I - 1))
[ $I -lt 0 ] && break
sleep 1
done
{
flock -x 278
ID=$2
grep -v "#$ID#\$" $F >$N 2>/dev/null
if [ "$1" = "a" ]; then
@ -23,8 +18,8 @@ if [ $# -gt 1 -a "$1" = "a" -o "$1" = "d" ]; then
fi
mv $N $F
echo root >>$U
} 278>$L
echo >$L
exit 0
fi

Loading…
Cancel
Save