Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!jeff From: jeff@tc.fluke.COM (Jeff Stearns) Newsgroups: comp.mail.misc Subject: Re: Mail locking... Message-ID: <7521@fluke.COM> Date: 31 Mar 89 22:56:45 GMT References: <588@dtscp1.UUCP> Sender: news@tc.fluke.COM Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 81 In article <588@dtscp1.UUCP> scott@dtscp1.UUCP (Scott Barman) writes: > I am trying to write some software for mail that will interact with our > internal network and must co-exist with the mailers on our bsd-based > systems (actually, SunOS 3.5 and SunOS 4.0) and with a System V Release > 3.2 system. I need to know how these systems lock the mail file. > Does /usr/.../*.lock work on both of these? I know that our v7-like > system uses the execute bit, but I do not have the sources to the other > systems. > > scott barman {gatech, emory}!dtscp1!scott Scott, I had the unfortunate occasion to study mailbox locking under SunOS 4.0; my findings might be of interest to you and others on the net. This was originally submitted to Sun as a bug report. They didn't follow up on it, so I can't say whether things are likely to change in the future. Jeff Stearns jeff@tc.fluke.COM John Fluke Mfg. Co, Inc. (206) 356-5064 ------------------------------------------------------------------------ Date: Thu, 25 Aug 88 16:42:44 PDT From: jeff (Jeff Stearns) To: rdk@sun.com Subject: /usr/ucb/mail doesn't follow /bin/mail lock protocol Cc: jhc@sun.com Status: R Name: Jeff Stearns Phone Number: 206/356-5064 Site: John Fluke Mfg. Co., Inc. PAL #: FLUKE-MF01 Subject: /usr/ucb/mail doesn't follow /bin/mail lock protocol Index: usr.ucb/mail SunOS 4.0 Description: - /bin/mail locks a user's mailbox with flock("/var/spool/mail/user") before delivery. This is good. - /usr/ucb/mail follows a different strategy which is guaranteed to fail: creat("/var/spool/mail/user.lock"); This can never succeed because the permissions of /var/spool/mail forbid file creation. (This is for security reasons.) - Thus /usr/ucb/mail manipulates mailboxes without the benefit of any locking. This leads to garbled messages and mangled mailboxes if /bin/mail delivers a message at the same time that /usr/ucb/mail is manipulating the mailbox. /bin/mail delivers a message at the same time that /usr/ucb/mail is manipulating the mailbox. Repeat-By: Nondeterminism forbids an exact recipe. Receive a lot of mail while you are running /usr/ucb/mail. Better yet, run trace(1) or inspect the code. Related-bug: - You may note that /bin/mail actually tries to follow two schemes for locking a mailbox. It repeatedly tries the creat("/var/spool/mail/user.lock"); of /usr/ucb/mail, but this fails (/bin/mail runs as the target uid at the instant of delivery). After this fails seven times, it gives up and simply flocks the mailbox file. /bin/mail's repeated fiddling with /var/spool/mail/user.lock is probably also a bug. -- Jeff Stearns John Fluke Mfg. Co, Inc. (206) 356-5064 jeff@tc.fluke.COM {uw-beaver,microsoft,sun}!fluke!jeff PS - Calling all users of the Vitalink TransLAN IV Ethernet bridge! Please drop me a line.