jbho has asked for the wisdom of the Perl Monks concerning the following question:

Venerable ones,
The question is "what to do about those alarm timeouts we've been using pre-5.8?" For syscalls in 5.8, the opcode/XS code has to finish/raise a signal/time out before returning to our code, rendering our signal timeout setting ineffectual.
Illustration:
#!/usr/bin/perl -w use strict; use Time::HiRes qw( gettimeofday tv_interval ); print "$]\n"; my $elapsed = 0; my $start_time = [gettimeofday]; eval { local $SIG{ALRM} = sub { $elapsed = tv_interval( $start_time ); warn "alarm-timeout signal"; die; }; alarm(1); `ls -R / 2>/dev/null`; alarm(0); }; print "$@" if $@; print "$elapsed\n";
Output on 5.6:
5.006 alarm-timeout signal at /home/jbho/bin/test_SIGALRM.pl line 15. Died at /home/jbho/bin/test_SIGALRM.pl line 16. 0.999504
Output on 5.8:
5.008 alarm-timeout signal at /home/jbho/bin/test_SIGALRM.pl line 15. Died at /home/jbho/bin/test_SIGALRM.pl line 16. 109.948451
Suggestion put out by member(s) of the community:
use POSIX ':signal_h'; my $alarm = 0; sigaction SIGALRM, new POSIX::SigAction sub { $alarm = 1 } or die "Error setting SIGALRM handler: $!\n";
This solution would bypass the perl implementation for setting the signal.
What say you?

Replies are listed 'Best First'.
Re: How to deal with safe signals in 5.8.0?
by Limbic~Region (Chancellor) on Jul 25, 2003 at 18:48 UTC
    jbho,
    5.8.1 RC 2 allows you to restore the unsafe signal handling. It is a compile time option - I recommend reading the delta file. Unfortunately, I do not know if there is a way to have your cake and eat it to in 5.8.0. I wouldn't rush into 5.8.1 release candidate 2 until the official release since there are known problems

    Cheers - L~R