Subject: Mail Lock...

From: "Isaias Callejas Mancilla." <[email-masked]>
Date: Mon, 29 Nov 1993 16:09:49 -0600 (CST)

Hi Dear List,
	I have got a question that is not for PINE really, I want to know
how (and why) the system generate the locked's files???...
	In the past, I have got some problems with it.... 

  Thank's in advance...

      /#######               E. Isaias Callejas M.
    /#       /############   Group System Managers from Microvax 3400 System
  /##      /##############   Coordination of Computing Services
  ###    /##           ###   Academic Computing
  ###    ###           ###   National University of Mexico
  ###    ##########    ###
  ###           ###    ###  =================================================
  ###           ##/    ###  
  ##############/      ##/   Internet :  [email-masked]
  ############/       #/     Bitnet   :  [email-masked]
              #######/

---

From: Mark Crispin <[email-masked]>
Date: Tue, 30 Nov 1993 07:55:29 -0800 (PST)

> 	In the past, I have got some problems with it....

I am not sure what you mean, but perhaps this information will help:

Locks are used by Pine and other mail programs to prevent damage from
occurring to the mail file when multiple programs try to write to the file at
the same time.

Because there are many different schemes of mail file locking used on UNIX,
Pine implements all of them.  The result is a lot of complexity.

There are several reasons why locking needs to be done:

1) If you want to read the mail file, you want to make sure that no other
   process will modify the mail file while you are reading it.

2) If you want to write to the mail file, you want to make sure that no other
   process is accessing the mail file while you are writing it.

3) If you have the mail file open, you want to make sure that no other process
   can alter any of the internal contents of the mail file that you have read,
   but it is OK if another process appends new data to the mail file.

4) If you want to alter any of the internal contents of the mail file, you
   want to make sure that no other process has the mail file open.

There are several mechanisms of locking:

a) The creation of a file which has the same name as the mail file, but with
   a suffix of ".lock" (for example, this lock for /usr/spool/mail/isma is
   named /usr/spool/mail/isma.lock).  This file accomplishes locks (1) and (2)
   above.  This is an exclusive lock.
b) The use of an flock() with LOCK_SH on the mail file.  This accomplishes
   lock (1), and prevents lock (2).  Multiple processes can do this.
c) The use of an flock() with LOCK_EX on the mail file.  This accomplishes
   lock (2), and prevents lock (1).  This is an exclusive lock.
d) The use of an flock() with LOCK_EX on a file on /tmp.  The file name used
   depends upon the version of Pine.  This accomplishes locks (3) and (4).
   This is an exclusive lock.

On SVR4-based systems, the lockf() subroutine or fcntl() system call it used
instead of flock().  It is rumored that this creates a kind of lock file as
well, but this has not been directly verified.

Regards,

-- Mark --