in reply to File::lockf and the lock() return value
First off, i'd highly suggest using flock() if at all possible.
The big limitation here is that File::lockf is a Perl binding to the SYSV lockf(3) call. Since lockf(3) will never return a 9, my guess is that the Perl binding (File::lockf) is returning the value that errno is set to.
Now the next hurdle; how do you figure out what an errno value corresponds to? ... with the strerror(3) (POSIX/SYSV/BSD/ISO 9899, etc) call. OOOoooh loook, it conforms to POSIX! =) That means that we're in luck (*this* time), since Perl has a fairly complete POSIX module.
The short answer (this is barebones, no strict or anything... and *just* a snippet):
The real answer: flock
=)
Update: I forgot to mention, in this case, with a status of '9', the error is "Bad file descriptor". This means that something was wrong with your filehandle.
The big limitation here is that File::lockf is a Perl binding to the SYSV lockf(3) call. Since lockf(3) will never return a 9, my guess is that the Perl binding (File::lockf) is returning the value that errno is set to.
Now the next hurdle; how do you figure out what an errno value corresponds to? ... with the strerror(3) (POSIX/SYSV/BSD/ISO 9899, etc) call. OOOoooh loook, it conforms to POSIX! =) That means that we're in luck (*this* time), since Perl has a fairly complete POSIX module.
The short answer (this is barebones, no strict or anything... and *just* a snippet):
use POSIX; use File::lockf; $status = File::lockf::lock ($args); # replace $args as appropriate. if ($status) { # Uh oh, non zero value returned. # Lets use POSIX's errstr() to find out what happened $error_string = strerror ($status); die "Uh oh, lockf returned '$error_string'"; }
The real answer: flock
=)
Update: I forgot to mention, in this case, with a status of '9', the error is "Bad file descriptor". This means that something was wrong with your filehandle.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 2: File::lockf and the lock() return value
by tilly (Archbishop) on Jan 12, 2002 at 21:46 UTC | |
by count0 (Friar) on Jan 14, 2002 at 19:47 UTC |
In Section
Seekers of Perl Wisdom