diff options
author | Paul Fenwick <pjf@perltraining.com.au> | 2008-09-17 06:32:39 +1000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2008-09-17 07:01:00 +0000 |
commit | 7ed5353dcffcb7d6cb842413f3f29c4dc6074e95 (patch) | |
tree | 069dff9996145a6f4e8e0dcd3a78f8d808cc38ac /pod | |
parent | f89542f789fc8ac88f7cd7e93bb8d9cd6228182b (diff) | |
download | perl-7ed5353dcffcb7d6cb842413f3f29c4dc6074e95.tar.gz |
Re: [PATCH] Revised: Improved documentation for flock() in perlfunc.pod
Message-ID: <48CF8B47.30803@perltraining.com.au>
p4raw-id: //depot/perl@34378
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlfunc.pod | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index ffd2ab3275..8e321ef84f 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1935,25 +1935,27 @@ perl. Here's a mailbox appender for BSD systems. - use Fcntl ':flock'; # import LOCK_* constants + use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants sub lock { - flock(MBOX,LOCK_EX); - # and, in case someone appended - # while we were waiting... - seek(MBOX, 0, 2); + my ($fh) = @_; + flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n"; + + # and, in case someone appended while we were waiting... + seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; } sub unlock { - flock(MBOX,LOCK_UN); + my ($fh) = @_; + flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; } open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}") or die "Can't open mailbox: $!"; - lock(); + lock($mbox); print $mbox $msg,"\n\n"; - unlock(); + unlock($mbox); On systems that support a real flock(), locks are inherited across fork() calls, whereas those that must resort to the more capricious fcntl() |