[comp.unix.wizards] How are mailfiles locked under 4.n and System III/V?

jack@mcvax.cwi.nl (Jack Jansen) (05/13/87)

A question for various wizards out there:

How do various unices lock mailfiles?

I know about V7 (make a file /usr/tmp/lock.USERNAME, yuck) and
2.9BSD (set the execute bits, slightly-less-yuck), but not how
other unices do this.

I would be very grateful if people who know could tell me.

(As an aside, I went through the sources of 4.3 sendmail,
expecting an flock() call or something similar,
but couldn't find *anything* that resembled locking. What am I
missing?)
-- 
	Jack Jansen, jack@cwi.nl (or jack@mcvax.uucp)
	The shell is my oyster.

chris@mimsy.UUCP (Chris Torek) (05/14/87)

In article <7384@boring.mcvax.cwi.nl> jack@mcvax.cwi.nl (Jack Jansen) writes:
>I know about V7 (make a file /usr/tmp/lock.USERNAME, yuck) and
>2.9BSD (set the execute bits, slightly-less-yuck), but not how
>other unices do this.

4.3BSD /bin/mail (not sendmail) uses flock().  4.1 and 4.2 /bin/mail
use a V7 style scheme, but the filename is /usr/spool/mail/USERNAME.lock.
Sun Unices still use the 4.2 scheme, at least up through Sun 3.0.

Mail file locking is one of those horrible things that is different
everywhere: we had hacked our software to use flock under 4.2BSD.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	seismo!mimsy!chris

mkhaw@teknowledge-vaxc.ARPA (Michael Khaw) (05/14/87)

In article <7384@boring.mcvax.cwi.nl> jack@mcvax.cwi.nl (Jack Jansen) writes:

>How do various unices lock mailfiles?

Ultrix 1.2 appears (we don't have source) to use flock().  I deduce this
from having to #define MAIL_USE_FLOCK for Gnu Emacs' movemail utility to
get it to work.

Mike Khaw
-- 
internet:  mkhaw@teknowledge-vaxc.arpa
usenet:	   {hplabs|sun|ucbvax|decwrl|sri-unix}!mkhaw%teknowledge-vaxc.arpa
USnail:	   Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

kyle@xanth.UUCP (05/15/87)

In article <7384@boring.mcvax.cwi.nl>, jack@mcvax.cwi.nl (Jack Jansen) writes:
> How do various unices lock mailfiles?

4.2 BSD uses /usr/spool/mail/USERNAME.lock .  4.3 BSD uses flock(), which is
nice now that flock() actually works.

> (As an aside, I went through the sources of 4.3 sendmail,
> expecting an flock() call or something similar,
> but couldn't find *anything* that resembled locking. What am I
> missing?)

Sendmail doesn't do local mail delivery.  Sendmail invokes /bin/mail to the
the actual message delivery.

dave@lsuc.UUCP (05/15/87)

We run v7 mail as our mail delivery agent, and 4.1BSD Mail (modified
to suit our needs) for interactive reading & sending.  I just went
through the exercise of giving them the same locking mechanism, after
getting bitten once too often and losing mail.

v7 mail locks by turning on the "other x" bit of the file with
chmod(2) (i.e., st_mode|01).  4.1BSD Mail locks by link(2)'ing to
/usr/spool/mail/username.lock.

David Sherman
The Law Society of Upper Canada
-- 
{ seismo!mnetor  cbosgd!utgpu  watmath  decvax!utcsri  ihnp4!utzoo } !lsuc!dave

henry@utzoo.UUCP (Henry Spencer) (05/20/87)

> I know about V7 (make a file /usr/tmp/lock.USERNAME, yuck) and
> 2.9BSD (set the execute bits, slightly-less-yuck)...

Actually considerably-*more*-yuck, because the execute-bits approach has
race conditions that can result in lost mail and corrupted mailboxes.  I
fixed this here after it happened to *my* mailbox once too often.
-- 
"The average nutritional value    Henry Spencer @ U of Toronto Zoology
of promises is roughly zero."     {allegra,ihnp4,decvax,pyramid}!utzoo!henry

brandon@tdi2.UUCP (Brandon Allbery) (05/25/87)

Quoted from <962@xanth.UUCP> ["Re: How are mailfiles locked under 4.n and System III/V?"], by kyle@xanth.UUCP (kyle jones)...
+---------------
| In article <7384@boring.mcvax.cwi.nl>, jack@mcvax.cwi.nl (Jack Jansen) writes:
| > How do various unices lock mailfiles?
| 
| 4.2 BSD uses /usr/spool/mail/USERNAME.lock .  4.3 BSD uses flock(), which is
| nice now that flock() actually works.
+---------------

Just to round it out:  System III/V use the 4.2BSD method, except that since
mail is in /usr/mail/* rather than /usr/spool/mail/*, the name of the lockfile
is `/usr/mail/USERNAME.lock'.

++Brando
-- 
Brandon S. Allbery	           UUCP: cbatt!cwruecmp!ncoast!tdi2!brandon
Tridelta Industries, Inc.         CSNET: ncoast!allbery@Case
7350 Corporate Blvd.	       INTERNET: ncoast!allbery%Case.CSNET@relay.CS.NET
Mentor, Ohio 44060		  PHONE: +1 216 255 1080 (home +1 216 974 9210)