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

Loading…
Cancel
Save