I didn't write it, and I don't know Perl very well at all.
We know. Regardless you have come to the right place for help.
The purpose of a lockfile is to tell other processes (ie copies of a CGI) to bugger off and wait their turn.
Anyway here is a pure Perl replacement that is identical to the lockfile call (well it is not IDENTICAL) because this actually works as the system call to lockfile should....
my $got_lock; use Fcntl; # to get constants for O_CREAT | O_EXCL | O_RDWR for ( 0 .. 5 ) { if ( sysopen(my $fh, "$base_dir/.lock", O_CREAT | O_EXCL | O_RDWR, + 0600) ) { $got_lock = 1; close $fh; last; } sleep 2; } diehtml("Lock error $!\n") unless $got_lock;
That should be a cut and paste replacement for this:
system ("lockfile -2 -r 5 $base_dir/.lock") == 0 or diehtml("Lock error: ", $? >> 8, "\n"); # TODO stop stderr of system
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Re: Re: Perl script crashing at lockfile ?
by tachyon
in thread Perl script crashing at lockfile ?
by peterr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |