Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!spool.mu.edu!usenet.eel.ufl.edu!news.mathworks.com!howland.erols.net!cliffs.rs.itd.umich.edu!newsxfer2.itd.umich.edu!uunet!in1.uu.net!38.8.16.2!psinntp!psinntp!atlas.jcpenney.com!chaos.taylored.com!drown From: drown@chaos.taylored.com (drown ) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Locking master.passwd correctly Date: 26 Dec 1996 03:34:32 GMT Organization: JCPenney Co., Inc. Lines: 30 Message-ID: <59sro8$l1a@atlas.jcpenney.com> NNTP-Posting-Host: 206.53.224.58 X-Newsreader: TIN [version 1.2 PL2] Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:33083 Hi folks, I've had some weird problems lately with chfn stomping over my account creation software. It seems that chfn doesn't "see" my lock on the master.passwd file sometimes, even though at other times it does. It seems to be a race condition. Here's the relivant perl code for locking the password file: open(MPW, "</etc/master.passwd") || die "cant locate $masterpw?!?!\n"; if (!flock(MPW, 6)) { close(MPW); while(1) { open(MPW, "</etc/master.passwd"); if (flock(MPW, 6)) { # Got it last; } close(MPW); sleep(5); } } Seems like it should work. The strange thing is that it usually _does_ work, it's just that every so often a user edits their info via chfn and boom, problems. I've confirmed this by patching pwd_mkdb to log when it's called. Any ideas what could be causing this? Am I locking the file incorrectly? Thanks! drown@chaos.taylored.com