J
janedunnie
Hi,
I'm in the process of transferring code to a new Linux machine, with a
newer version of Perl (Perl 5.8.5), and also cleaning up the code to
run under mod_perl. However, I'm having problems with some code that
I've previously used, which no longer appears to work under the new
config. I understand from scouring the web that signal handling
changed in 5.8+, but despite trying every method I could find, I still
can't get it to work under mod_perl. However, each method works
outside of mod_perl.
The original code was similar to this:
eval
{
local $SIG{ALRM} = sub {die "alarm\n"};
alarm 5;
system('some command');
alarm (0);
};
New code which I've tried under 5.8, and which works outside of
mod_perl, includes the following:
use POSIX qw(SIGALRM);
POSIX::sigaction(SIGALRM, POSIX::SigAction->new(sub{die "alarm"})) or
die "Error setting SIGALRM handler: $!\n";
eval{
alarm 5;
system('some command');
alarm (0);
};
POSIX::sigaction(SIGALRM, $oldaction);
Other new code which I've tried, and which also works outside of
mod_perl, is as follows:
use Sys::SigAction qw(timeout_call);
if (timeout_call(5, sub{my $retval=&test();}))
{
print "timed out\n";
};
sub test{
system('some command');
}
When I say that these methods "don't work" under mod_perl I mean that
the processes simply continue without waiting for the alarm. They
don't error ... they just don't wait for the specified command(s) to
finish.
So, I'm wondering what kind of work-around there may be, or what
alternative method of handling time-outs may exist in mod_perl under
5.8.x.
Any assistance much appreciated.
Thanks!
Jane
I'm in the process of transferring code to a new Linux machine, with a
newer version of Perl (Perl 5.8.5), and also cleaning up the code to
run under mod_perl. However, I'm having problems with some code that
I've previously used, which no longer appears to work under the new
config. I understand from scouring the web that signal handling
changed in 5.8+, but despite trying every method I could find, I still
can't get it to work under mod_perl. However, each method works
outside of mod_perl.
The original code was similar to this:
eval
{
local $SIG{ALRM} = sub {die "alarm\n"};
alarm 5;
system('some command');
alarm (0);
};
New code which I've tried under 5.8, and which works outside of
mod_perl, includes the following:
use POSIX qw(SIGALRM);
POSIX::sigaction(SIGALRM, POSIX::SigAction->new(sub{die "alarm"})) or
die "Error setting SIGALRM handler: $!\n";
eval{
alarm 5;
system('some command');
alarm (0);
};
POSIX::sigaction(SIGALRM, $oldaction);
Other new code which I've tried, and which also works outside of
mod_perl, is as follows:
use Sys::SigAction qw(timeout_call);
if (timeout_call(5, sub{my $retval=&test();}))
{
print "timed out\n";
};
sub test{
system('some command');
}
When I say that these methods "don't work" under mod_perl I mean that
the processes simply continue without waiting for the alarm. They
don't error ... they just don't wait for the specified command(s) to
finish.
So, I'm wondering what kind of work-around there may be, or what
alternative method of handling time-outs may exist in mod_perl under
5.8.x.
Any assistance much appreciated.
Thanks!
Jane