From owner-freebsd-current Thu Nov 16 9:46:49 2000 Delivered-To: freebsd-current@freebsd.org Received: from guru.mired.org (okc-65-26-235-186.mmcable.com [65.26.235.186]) by hub.freebsd.org (Postfix) with SMTP id 83A2637B479 for ; Thu, 16 Nov 2000 09:46:40 -0800 (PST) Received: (qmail 64327 invoked by uid 100); 16 Nov 2000 17:46:39 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14868.7551.791920.252398@guru.mired.org> Date: Thu, 16 Nov 2000 11:46:39 -0600 (CST) To: "Andresen,Jason R." Cc: Garrett Wollman , void , freebsd-current@FreeBSD.ORG Subject: Re: Proper permissons on /var/mail In-Reply-To: <3A1412C1.96608727@mitre.org> References: <20001116151809.A15312@firedrake.org> <200011161636.LAA83126@khavrinen.lcs.mit.edu> <3A1412C1.96608727@mitre.org> X-Mailer: VM 6.75 under 21.1 (patch 10) "Capitol Reef" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Andresen,Jason R. types: > Garrett Wollman wrote: > > > > < said: > > > > > I have a similar problem -- every time I make world, perms on /var/mail > > > get set to 775. Mutt considers my mailbox read-only until I change it > > > to 1777. > > > > It is misconfigured (or perhaps just broken). 1777 mode for /var/mail > > is insecure, but was necessary in the mists of ancient past, before > > UNIX learned to do file locking. Unless your mail spool is shared > > over NFS (don't do that), locking is reliable and .lock files should > > never be used or relied upon. > > Not the FreeBSD's file locking works anyway. > Here's the results from a test of the below program: I can see at least two problems with the test program. 1) You're locking a shared descriptor. Possibly that should work, but it's not a case I normally see. Moving the open after the fork makes this behave better. 2) You're depending on a synchronization between the two process, but not doing anything to insure it. The correct test is not that the last message was the child string, but that the last two messages are the same. Actually, my first test was to change this to "lock, prompt, write, unlock, exit", then run it in two windows. The first process pauses - with the file locked - and the second hangs until the user responds to the prompt. (81 ~/bin/src): uname -a > FreeBSD escaflowne.el.hazard 4.1.1-STABLE FreeBSD 4.1.1-STABLE #0: Sat > Oct 14 18:59:16 EDT 2000 > root@escaflowne.el.hazard:/usr/obj/usr/src/sys/ESCAFLOWNE i386 > (82 ~/bin/src): ./testflock > flock(2) is implemented, but not functional. > > And another test: > %kenshin (1 ~): uname -a > IRIX kenshin 6.5 01221642 IP20 > %kenshin (2 ~): ./testflock > flock(2) is fully functional. > > I hope I'm doing something wrong here, and that flock really does work > on FreeBSD. > > #include > #include > #include > #include > #include > #include > > #define TMPFILENAME "/tmp/testflock.out" > #define MESSLEN 8 > #define CHILDSTR "Child \n" > #define PARENTSTR "Parent\n" > > int main( int argc, char** argv) > { > char message[MESSLEN]; > int pid; > int fd; > int foo; > > fd = open(TMPFILENAME, O_WRONLY | O_CREAT, 0644); > > pid = fork(); > > if ( pid == 0 ) > { > strcpy(message, CHILDSTR); > sleep(1); > } > else > strcpy(message, PARENTSTR); > > > flock(fd, LOCK_EX); > > lseek(fd, 0, SEEK_END); > write(fd, message, MESSLEN - 1); > > sleep(2); > > lseek(fd, 0, SEEK_END); > write(fd, message, MESSLEN - 1); > > flock(fd, LOCK_UN); > > close(fd); > > if ( pid != 0 ) > { > wait(&foo); > > /* Test the file, see if flock works */ > fd = open(TMPFILENAME, O_RDONLY); > > read(fd, (void*)message, MESSLEN - 1); /* Discard first > */ > read(fd, (void*)message, MESSLEN - 1); > > if (! strcmp(message, CHILDSTR)) > printf("flock(2) is implemented, but not > functional.\n"); > else > printf("flock(2) is fully functional.\n"); > > close(fd); > } > > return 0; > } > > > -- > _ _ _ ___ ____ ___ ______________________________________ > / \/ \ | ||_ _|| _ \|___| | Jason Andresen -- jandrese@mitre.org > / /\/\ \ | | | | | |/ /|_|_ | Views expressed may not reflect those > /_/ \_\|_| |_| |_|\_\|___| | of the Mitre Corporation. > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-current" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message