Fixing the race condition in shlock.c
Berend Reitsma
breitsma+inn at gmail.com
Thu Oct 16 13:45:53 UTC 2008
Hi,
Back in 2002 I sent a bug report about a race condition in shlock.c
when removing a presumed old lock file. In the mean time I managed to
create a fix for this. I am actually using this as a standalone
locking program in the scripts I have written and I'm not able to
reproduce the race condition with my modification again.
If somebody is interested in having the fix I can post it here. If
nobody cares about fixing a nice race condition in the shlock program
I won't bother you again ;)
The trick comes down to locking access to the file you want to remove
by linking to it and checking the number of links and the inode before
removing it.
The code I have is based on revision 1.6 and has a number of
differences w.r.t the original in that it does not include clibrary.h
and configdata.h but has the necessary definitions in the source.
And in case somebody wants to test the race condition:
-----
#!/bin/bash
cmd='if shlock -p $$ -f testlock.pid; then echo -e "$PPID
\r\c";p=`cat testlock.pid`
[ $? -eq 0 ] && [ $$ -eq $p ] || echo "shlock race condition,
testlock.pid=\"$p\" \$\$=\"$$\""
fi'
pids=""
for n in x x x x x x x x x x; do
(trap "exit 0" 15; while :; do bash -c "$cmd"; done) &
pids="$pids $!"
done
sleep 30
kill $pids
wait
-----
Regards,
Berend.
More information about the inn-workers
mailing list