Subject: Need details on mailbox locking

From: [email-masked] (Randall C. Nortman)
Date: 17 Jan 1997 03:42:58 GMT

I'm writing a program which operates on mailboxes on a unix system
(specifically, Solaris, but I want to make it portable).  I'm
concerned about file locking, since I don't really know that much
about it, having learned programming on OS/2 where file locking is
handled by the OS.  I know that one can use the flock() call, and also
that programs often create a file named FileToLock.lock, where
"FileToLock" is replaced, of course, with the name of the file to
lock.  If I do both, however, I could get into deadlock with another
program.  (For example, I create file.lock and then try to
flock(file).  Another prog has already flock'ed(file), and is waiting
for file.lock to disappear.)

I'm particularly concerned with coexisting peacefully with Pine.

So, if somebody can provide me with some details about this it would
be very helpful.  Sample code (preferably in C/C++ or Perl, but I know
quite a few other langs as well) would be imminently useful.  Or,
simply pointing me to some good docs would be fine.  (I've found the
mail filtering FAQ and the Pine Q & A and tech-notes already, which
were useful but didn't give enough detail.)

TIA.  Any help greatly appreciated.

-- 
Randy Nortman
[email-masked]
http://www.tezcat.com/~rnortman

---

From: Rudolf Kompf <[email-masked]>
Date: Mon, 20 Jan 1997 10:01:55 +0100 (MET)

On 17 Jan 1997, Randall C. Nortman wrote:

-> I'm writing a program which operates on mailboxes on a unix system
-> (specifically, Solaris, but I want to make it portable).  I'm
-> concerned about file locking, since I don't really know that much
-> about it, having learned programming on OS/2 where file locking is
-> handled by the OS.  I know that one can use the flock() call, and also
-> that programs often create a file named FileToLock.lock, where
-> "FileToLock" is replaced, of course, with the name of the file to
-> lock.  If I do both, however, I could get into deadlock with another
-> program.  (For example, I create file.lock and then try to
-> flock(file).  Another prog has already flock'ed(file), and is waiting
-> for file.lock to disappear.)
-> 
-> I'm particularly concerned with coexisting peacefully with Pine.
-> 
-> So, if somebody can provide me with some details about this it would
-> be very helpful.  Sample code (preferably in C/C++ or Perl, but I know
-> quite a few other langs as well) would be imminently useful.  Or,
-> simply pointing me to some good docs would be fine.  (I've found the
-> mail filtering FAQ and the Pine Q & A and tech-notes already, which
-> were useful but didn't give enough detail.)
-> 
-> TIA.  Any help greatly appreciated.
-> 
-> -- 
-> Randy Nortman
-> [email-masked]
-> http://www.tezcat.com/~rnortman
-> 
I have installed the procmail-package. It contains a command 'lockfile',
which can be used to create semaphore files (calls have time-outs and
retries!). These files are compatible with procmail's mail-file handling.

So I process all mail with procmail's private lockfiles and lock with
command 'lockfile' these lockfiles from inside of my shell-scripts.

-----------------------------------------------------------------------
Rudolf Kompf                     | E-mail: [email-masked]