setlock oddity - stale lock file?

Charles Cazabon <[email protected]> Thu, 14 Jun 2007 09:16:17 -0600
Newsgroups gmane.comp.djb.syslog
Message-ID <[email protected]>
Greetings,

I've run into a situation where setlock appears to have stopped running it's
child due to the presence of a stale lockfile, which I thought it was immune
to.

I have a cron job to run `getmail` to pull my mail on a fairly frequent basis
(every 5 minutes).  I use setlock to avoid having two copies run
simultaneously (if it were to take longer than 5 minutes to complete), like
this:

  0-59/5 7-17 * * * ~/bin/setlock -nx /tmp/getmail.lock getmail -q

This normally works fine.  Yesterday morning I had a five-second power outage
around 7:20am that killed the computer this runs on.  The system booted fine
after the power came back.  The cron logs show that cron kept running that
cronjob all day:

  Jun 13 07:30:01 mendelev /USR/SBIN/CRON[9355]: (ccazabon) CMD (~/bin/setlock
  -nx /tmp/getmail.lock getmail -q)
  [...]
  Jun 13 11:20:01 mendelev /USR/SBIN/CRON[13416]: (ccazabon) CMD
  (~/bin/setlock -nx /tmp/getmail.lock getmail -q)
  [...]

However, getmail appears to have not been run (no mail was retrieved, though
there were 25 new messages on the server).  When I noticed this oddity this
morning, I removed the lock file /tmp/getmail.lock, and the mail showed up the
next time the cronjob was run.

So it appears setlock thought the lock file was locked, even though there was
no process with it open, etc.  I didn't think setlock was susceptible to this
type of problem.

System info:  Linux 2.6.x (Ubuntu) running on a 64-bit dual-Opteron workstation.

Can anyone explain what happened here?

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon                              <[email protected]>
GPL'ed software available at:               http://pyropus.ca/software/
-----------------------------------------------------------------------