Perl and File Locking
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Oct 15 14:15:00 GMT 2013
On Sep 25 08:25, Warren Young wrote:
> On 9/25/2013 02:24, wynfield@gmail.com wrote:
> >
> >"Your vendor has not defined Fcntl macro O_EXLOCK,"
>
> O_EXLOCK is a BSD feature, and Cygwin tries to emulate Linux, not BSD.
>
> Minimal testing tells me you can use Cygwin's nonstandard
> F_LCK_MANDATORY feature from Perl. This script, foo.pl, doesn't
> die:
>
> #!/usr/bin/perl
> sysopen my $fh, "foo.pl", 0600, O_RDONLY or die "sysopen: $!\n";
> fcntl $fh, 0x99, 1 or die "fcntl: $!\n";
>
> Whether it actually does what you expect is a different question.
Uh, no, don't do that. O_EXLOCK in the BSD world does *not* mean that
you want mandatory locking. It only means that the application wants an
exclusive lock on the entire file right at open time, thus allowing an
atomic open/lock under BSD flock semantics.
What you want to do is to call
sysopen my $fh, "foo.pl", 0600, O_RDONLY ...
[insert perl equivalent of the flock system call here]
That's not atomic, but this isn't provided (yet) utside the BSD world.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20131015/63fd52f1/attachment.sig>
More information about the Cygwin
mailing list