in reply to Re: SIGALRM and gethostbyaddr
in thread SIGALRM and gethostbyaddr

it's also possible to set an unsafe signal with POSIX::sigaction, without switching the entire Perl program to unsafe signals. (Recent sigactions will actually let you set a signal safe or unsafe.)

It's worth noting, BTW, that unsafe signals are called "unsafe" for a reason. What you really need is a C signal handler in an XS or with Inline::C that can just return without causing even the slightest disturbance to Perl's interpreter state.

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re: Re: Re: SIGALRM and gethostbyaddr
by jfroebe (Parson) on Mar 18, 2004 at 16:15 UTC
    Here is the new code using use Sys::SigAction. Thanks!!!
    use Sys::SigAction qw( set_sig_handler ); .... eval { my $code = sub { die "alarm clock restart"; }; my $h = Sys::SigAction::set_sig_handler( 'ALRM', $code, { +flags => 0, safe => 1 } ); alarm 10; # schedule alarm for every 10 seconds eval { ($my_name, $my_aliases, $addrtype, $my_length, @my_add +r) = gethostbyname($my_hostname); }; alarm 0; }; alarm 0; die if $@ && $@ !~ /alarm clock restart/; #reraise
Re: Re: Re: SIGALRM and gethostbyaddr
by jfroebe (Parson) on Mar 18, 2004 at 15:33 UTC
    thanks to both of you... I'm doing mass lookups of about 4,000 ip addresses and a tiny amount don't resolve within a reasonable amount of time.. there are a tiny number that need to be looked up on other nameservers...