From owner-freebsd-hackers Tue Aug 24 2:20: 9 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from metriclient-1.uoregon.edu (metriclient-1.uoregon.edu [128.223.172.1]) by hub.freebsd.org (Postfix) with ESMTP id 0630615862 for ; Tue, 24 Aug 1999 02:20:03 -0700 (PDT) (envelope-from gurney_j@efn.org) Received: (from jmg@localhost) by metriclient-1.uoregon.edu (8.9.1/8.8.7) id CAA22663; Tue, 24 Aug 1999 02:14:31 -0700 (PDT) Message-ID: <19990824021431.55023@hydrogen.fircrest.net> Date: Tue, 24 Aug 1999 02:14:31 -0700 From: John-Mark Gurney To: Ville-Pertti Keinonen Cc: Greg Lehey , hackers@FreeBSD.ORG Subject: Re: Mandatory locking? References: <19990823223645.A14001@netmonger.net> <19990824131036.B83273@freebie.lemis.com> <86r9ktk25r.fsf@not.demophon.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.69 In-Reply-To: <86r9ktk25r.fsf@not.demophon.com>; from Ville-Pertti Keinonen on Tue, Aug 24, 1999 at 11:34:24AM +0300 Reply-To: John-Mark Gurney Organization: Cu Networking X-Operating-System: FreeBSD 3.0-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Ville-Pertti Keinonen scribbled this message on Aug 24: > > grog@lemis.com (Greg Lehey) writes: > > > an agreement of some kind. But what if I want to merge the contents > > of another mail folder: > > > cat oldmail >>/var/mail/grog > > > That works, but it's playing with fire: if sendmail is delivering a > > message at the same time, it won't see me, and my cat doesn't get a > > lock beforehand, so both an incoming message and part of my mail > > folder could end up getting written to the same location. With > > mandatory locking, it would work, transparently. > > Certainly not with range-locking rather than file-locking. cat is > certainly not guaranteed to be atomic, and while you shouldn't end up > writing things in the same location, what might happen unless you are > preventing multiple openers is: > > cat writes part of oldmail to /var/mail/grog > sendmail locks /var/mail/grog > (cat may try to write more to /var/mail/grog but blocks) > sendmail delivers new mail > sendmail unlocks /var/mail/grog > cat writes the rest of oldmail to /var/mail/grog > > You'll still probably end up with a broken mailbox. what you do is this: lockf -k $mailfile cat ${mailtmp} >> $mailfile then you don't have to worry.. that's what lockf is for... -- John-Mark Gurney Voice: +1 541 684 8449 Cu Networking P.O. Box 5693, 97405 "The soul contains in itself the event that shall presently befall it. The event is only the actualizing of its thought." -- Ralph Waldo Emerson To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message