Lock files always present?

Julian Field mailscanner at ecs.soton.ac.uk
Fri Aug 22 16:23:35 IST 2003


At 16:11 22/08/2003, you wrote:
>I'm totally confused about how the lock files work in MailScanner.
>
>I've noticed that I always have lock files for each virus engine in /tmp.
>For example, there is always a file called /tmp/FProtBusy.lock.  The text
>in the file says
>
>Virus checker locked for scanning by f-prot 18949
>
>When I check the pid 18949 it turns out to be one of the MailScanner
>processes.
>
>When I checked the f-prot-autoupdate script it never checks to see if the
>lock exists.  It just goes ahead and creates the lock file then proceeds
>to perform the pattern update process.  Just before the script exits it
>removes the /tmp/FProtBusy.lock file which is immediately created again by
>a MailScanner process???
>
>Could someone enlighten me on how this is really working?

Of the type of lock I use, there are 2 sorts of lock you can have on a
file. None of it uses just the fact that the file exists, that's irrelevant.

There are shared locks. Lots of processes can have a shared lock on the
same file at the same time. Each of the MailScanner processes has a shared
lock on the virus scanner lock file while the scanner is executing.

There are also exclusive locks. Only 1 process can have an exclusive lock
on a file at once. Furthermore, getting an exclusive lock stops other
processes from getting shared locks on the same file. When they try to get
their shared lock, they just wait until the exclusive lock is cleared. The
autoupdate scripts get an exclusive lock on the lock file while they are
actually updating the virus scanner. This means that while the update is
going on, none of the MailScanner processes can start to use the scanner as
they can't get their shared locks.

When a process ends, any remaining locks are automatically cleared by the
operating system. So it doesn't matter if you kill an autoupdate script
half way through (say while waiting for an FTP server that won't respond),
it will just unlock as it dies leaving the MailScanner processes running
normally.

There is no "clear-up" work to be done in order for the MailScanner
processes to be able to continue running. Most other locking systems
involve all sorts of fancy code to detect locks that have been there for a
long time, and delete these "stale" locks on the basis they probably
shouldn't be there. My method is simple and works well enough in this
environment.

The end result of all this is that the autoupdate script effectively locks
out *all* the MailScanner processes at once, stopping them from running the
scanner until the update has completed. At that point, it removes the lock
and all the MailScanner processes can start scanning again.

I write a line of info into the lock file so that
a) it contains something, and
b) it contains something that was useful to me when I was writing it.
--
Julian Field
www.MailScanner.info
MailScanner thanks transtec Computers for their support



More information about the MailScanner mailing list