Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Which signals are unsafe?

by Sprad (Hermit)
on Apr 01, 2004 at 23:06 UTC ( [id://341825]=perlquestion: print w/replies, xml ) Need Help??

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

Are all signals unsafe? Or just the alarm and interrupt signals? What about warn?

I wrote a handler for warnings to give me some more info when things break. But if the warning handler makes things break as well, then obviously I don't want to use it. Is this code bad?

Update: This is under ActiveState Perl 5.6.1, on WinXP

$SIG{__WARN__} = \&mywarn; # ... sub mywarn { my $warning = shift; my $i = 0; open (WRNLOG, ">>Warnings.log") || warn "Can't open warnings log f +ile: $!"; # If open failed, output will be discarded print STDOUT "WARNING: $warning"; print WRNLOG "WARNING: $warning"; print STDOUT " Stack Trace:\n"; print WRNLOG " Stack Trace:\n"; while (caller($i)) { my (undef, $filename, $line, $sub) = caller($i); print STDOUT " $filename ($line) --- $sub\n"; print WRNLOG " $filename ($line) --- $sub\n"; $i++; } print STDOUT "\n"; print WRNLOG "\n"; }

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: Which signals are unsafe?
by BrentDax (Hermit) on Apr 01, 2004 at 23:25 UTC

    $SIG{__WARN__} isn't a real signal, so it's safe. I believe that all signals have been safe since 5.8.

    Have you looked at the Carp module? It can be used with $SIG{__WARN__} to print backtraces. Perhaps you could do something like this:

    use Carp 'cluck'; $SIG{__WARN__}=\&cluck; open(STDERR, "|tee -a Warnings.log") or die "Can't open STDERR to tee: + $!";

    It's not exactly the same as what you have; most notably, all STDERR output would go to Warnings.log, not just warnings. Fixing this is left as an exercise for the reader. ;^)

    If nothing else, Carp's longmess sub can handle the backtracing for you.

    =cut
    --Brent Dax
    There is no sig.

Re: Which signals are unsafe?
by etcshadow (Priest) on Apr 01, 2004 at 23:20 UTC
    All real signals are potentially unsafe (in older perls). Warn, however, is not a real signal... it's a psuedo signal, and it's always been safe.
    ------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://341825]
Approved by Limbic~Region
Front-paged by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found