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,24 +7,19 @@ 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)) ID=$2
[ $I -lt 0 ] && break grep -v "#$ID#\$" $F >$N 2>/dev/null
sleep 1 if [ "$1" = "a" ]; then
done shift
shift
echo "$* #$ID#" >>$N
fi
mv $N $F
echo root >>$U
} 278>$L
ID=$2
grep -v "#$ID#\$" $F >$N 2>/dev/null
if [ "$1" = "a" ]; then
shift
shift
echo "$* #$ID#" >>$N
fi
mv $N $F
echo root >>$U
echo >$L
exit 0 exit 0
fi fi

Loading…
Cancel
Save