That makes sense to me. Trying to think of a solution, the first thing I came up with that would probably work is to write a signal reflector.

sub spawn { my $pid; if( $^O =~ /Win32/ ) { $pid= system( 1, @_ ); } else { # do something more complex with fork() and exec() # since Perl doesn't provide a portable way to spawn } return $pid; } my $mirror= spawn( $^X, 'mirror.pl', $$ ); my @sigs; $SIG{$_}= \&logSig for keys(%SIG); $SIG{USR1}= \&restoreHandlers; sub logSig { my $sig = shift @_; push @sigs, $sig; syslog( 'info', "Got signal '$sig'" ); $SIG{$sig}= 'DEFAULT'; kill $sig, $mirror; } sub restoreHandlers { my $sig= shift @_; if( ! @sigs ) { syslog( 'info', "Got signal '$sig'" ); } else { $SIG{$_} = \&logsig for @sigs; @sigs= (); } }

Then mirror.pl would be:

my $caller= shift @ARGV; $SIG{$_} = \&reflectSig for keys(%SIG); sub reflectSig { my $sig= shift @_; kill $sig, $caller; kill 'USR1', $caller; }

A bit complex, unfortunately. Of course, if you get sent the same signal twice, you might not log two lines; that is just how signals work.

In the unlikely event that signals have priorities and when a process has received both a USR1 and some other signal it could decide to process the USR1 before the other (even though the other came in first), that could cause problems.

- tye        


In reply to Re^2: Signal Question (mirror) by tye
in thread Signal Question by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.