Perl script crashing at lockfile ?

P

Peter Richards

Hi,

I've recently moved a website and one Perl script will not work. The
previous site had a Unix box with Perl 5.006 , and the new site has a
Linux box with Perl 5.006001

After inserting "print" statements all over the place, finally this
piece of code is where the script is stopping:

----------------------------------------------------------------------
system ("lockfile -2 -r 5 $base_dir/.lock" ) == 0 or diehtml("Lock
error: ", $? >> 8, "\n" ); # TODO stop stderr of system
--------------------------------------------------------------------

There is no msg appearing (what happened to the "diehtml" ?), the
script just stops. I have checked all the path and file permissions,
and they are exactly the same s the previous website. The variable
$base_dir has a value of '/home/username/public_html/.orders'

The 'shebang' line, etc is:

-----------------------------------------------
#!/usr/bin/perl -wT

use CGI qw/:standard/;
use DBI;

# resource limits
$CGI:DISABLE_UPLOADS = 1;
$CGI::pOST_MAX = 1024;
-----------------------------------------------

Any clues as to why this is stopping ?

Thanks,

Peter


Peter Richards
(e-mail address removed)
(but use hotmail to email)
 
A

Anno Siegel

Peter Richards said:
Hi,

I've recently moved a website and one Perl script will not work. The
previous site had a Unix box with Perl 5.006 , and the new site has a
Linux box with Perl 5.006001

Well, Linux is one kind of Unix. What you're saying is like, "I used
to have a car, but now I have a Chevy".
After inserting "print" statements all over the place, finally this
piece of code is where the script is stopping:

----------------------------------------------------------------------
system ("lockfile -2 -r 5 $base_dir/.lock" ) == 0 or diehtml("Lock
error: ", $? >> 8, "\n" ); # TODO stop stderr of system
--------------------------------------------------------------------

There is no msg appearing (what happened to the "diehtml" ?), the
script just stops. I have checked all the path and file permissions,
and they are exactly the same s the previous website. The variable
$base_dir has a value of '/home/username/public_html/.orders'

The "lockfile" command you are using is not a standard Unix command.
Some systems have it, some don't. With those that have it, the
behavior could differ. See the documentation for "lockfile" on
both systems.

[...]

Anno
 
P

Peter Richards

Hi Anno,

Well, Linux is one kind of Unix. What you're saying is like, "I used
to have a car, but now I have a Chevy".


The "lockfile" command you are using is not a standard Unix command.
Some systems have it, some don't. With those that have it, the
behavior could differ. See the documentation for "lockfile" on
both systems.

Yes, I asked on PerlMonks, and "robartes" replied:

"File locking is a tricky field that is very susceptible to
portability issues. Your problem is most probably situated in
different behaviour of lockfile between your original and current
systems"

and "tachyon" supplied a pure Perl replacement:

----------------------------------------------------------------------
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;
----------------------------------------------------------------------

Thanks,

Peter


Peter Richards
(e-mail address removed)
(but use hotmail to email)
 
M

Malcolm Dew-Jones

Peter Richards ([email protected]) wrote:
: Hi,

: I've recently moved a website and one Perl script will not work. The
: previous site had a Unix box with Perl 5.006 , and the new site has a
: Linux box with Perl 5.006001

: After inserting "print" statements all over the place, finally this
: piece of code is where the script is stopping:

: ----------------------------------------------------------------------
: system ("lockfile -2 -r 5 $base_dir/.lock" ) == 0 or diehtml("Lock
: error: ", $? >> 8, "\n" ); # TODO stop stderr of system
: --------------------------------------------------------------------

: There is no msg appearing (what happened to the "diehtml" ?), the
: script just stops.

What do you mean by "just stops"?

Is the script still running but not doing anything? I would use the ps
command to check. I typically type the command

$ ps -ef | grep my-user-name

to see what programs I am running, though how you do that on your cgi
server will depend.

I would guess the lockfile program is waiting to acquire a lock on the
flag file ($base_dir/.lock). I suspect that if you use ps you will see
the lockfile program "running", but not taking any time (because it is
just waiting), and your perl script will also be "running" but not taking
any time (because it too is waiting - for the lockfile program).

It could be that the web server will kill the processes if they stay stuck
too long, in which case you will not get an error message. It could be
that the lockfile program gets stuck just once (for reason I cannot
guess at) and then every time you run the perl-script/lockfile-program
then it will hang because of the earlier stuck process.

You could try an alarm around the system() call

# untested, from memory, some pseudo code
alarm(3); # three seconds
eval { system(your-command); }
alarm(0);
if ($@)
{ diehtml("system() timed out after three seconds");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top