Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!stl!robobar!ronald From: ronald@robobar.co.uk (Ronald S H Khoo) Newsgroups: comp.lang.perl Subject: Re: While learning PERL... a suggestion Message-ID: <1991Jan22.080310.5582@robobar.co.uk> Date: 22 Jan 91 08:03:10 GMT References: <118879@uunet.UU.NET> <1991Jan21.092204.11944@ux1.cso.uiuc.edu> <119430@uunet.UU.NET> Organization: Robobar Ltd., Perivale, Middx., ENGLAND. Lines: 36 rbj@uunet.UU.NET (Root Boy Jim) writes: > Another thing perl needs is the ability to create lock files. Sysopen? Eh ? You're not advocating the use of O_CREAT|O_EXCL for lockfiles are you ? That's not portable. It doesn't work on my machine for one :-) Why not do lockfiles like C News does them ? [ Question: did I get the $SIG{} = stuff right ? it's a little hard to test ..] # =()<$NEWSCTL = "@@";>()= $NEWSCTL = "/usr/lib/news"; $ltmp = "$NEWSCTL/LTMP.$$"; $lock = "$NEWSCTL/LOCK"; sub Handler { unlink($lock, $ltmp) if $locked; exit 1; } sub Lock { open (LTMP, ">$ltmp") || die "cannot write to $ltmp: $!\n"; print LTMP "$$\n"; close(LTMP); until ($locked) { if (link($ltmp, $lock)) { $locked = 1; } else { sleep 30; } } $SIG{'HUP'} = $SIG{'INT'} = $SIG{'TERM'} = 'Handler'; } sub UnLock { unlink ($lock, $ltmp) if $locked; $locked = 0; } -- Ronald Khoo +44 81 991 1142 (O) +44 71 229 7741 (H)