in reply to trouble with custom signal handlers

I might have been able to isolate the problem, it seems related to the use of the Safe module. This shows the problem:
use warnings; use strict; use Safe; our $mySafe = new Safe; sub handleSigs { my ($signalReceived) = @_; my $exitVal = 0; warn("warning: received $signalReceived signal"); if ($signalReceived eq "INT") { $exitVal = 1; } elsif ($signalReceived eq "USR1") { $exitVal = 2; } elsif ($signalReceived eq "USR2") { $exitVal = 3; } exit($exitVal); } $SIG{USR1}=\&handleSigs; $SIG{USR2}=\&handleSigs; $mySafe->reval("10 + 20"); print "My PID is $$\n"; sleep(100); print "Exiting\n";
Now I just need to dig documentation of the Safe module to find out what is going on with http://perldoc.perl.org/Safe.html

Replies are listed 'Best First'.
Re^2: trouble with custom signal handlers
by BrowserUk (Patriarch) on Apr 17, 2016 at 12:57 UTC

    Safe almost certainly uses signal handlers; and on the evidence of this code, it apparently doesn't restore any old ones.

    The solution might be to wrap reval() with code that saves and restores any existing signal handlers either side of calling that method.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks for the confirmation. I'll probably do what you suggest although it should really be fixed in the Safe module (why does Safe need to reset ALL signal handlers?). Otherwise I can see cases where a signal at the wrong time could have unpredictable effects.
        (why does Safe need to reset ALL signal handlers?)

        Because it is the only way to be Safe. Otherwise, the arrival of a signal could cause the signal handler code to be called; and it would be completely outside of Safe's control, and could do anything!

        But yes; it should restore what was there when it was called.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.