Wise Monks,

I'm working in a monitoring script that send messages to a monitoring server. This is working well, but now I have a little proble:

This script have to send an alarm when anything goes wrong with the monitored system, but also when anything goes wrong with himself, that is, it must send an alarm when it dies, or when it gets killed. The process of sending an alarm is appending a special message to a "special" "file"

I've accomplished that using some code like that:

local $SIG{'TERM'} = \&killalarm; local $SIG{'INT'} = \&killalarm; local $SIG{'__DIE__'} = \&diealarm; sub killalarm{ my $signal = shift; diealarm("Killed by signal $signal\n"); } sub diealarm{ my $params = shift; # some stuff, opening files, printing to files... }

But my problem is that I'm using an old perl version (5.005_03 built for sun4-solaris), and I can't change it. I know that there are some problems with signal handling in perl under before 5.7.x, and that it isn't recommended to do a lot of work in signal handlers. I've though on reformatting this code like that:

local $SIG{'TERM'} = \&killalarm; local $SIG{'INT'} = \&killalarm; local $SIG{'__DIE__'} = \&diealarm; sub killalarm{ my $signal = shift; die "Killed by signal $signal\n"; } sub diealarm{ my $params = shift; # a lot of stuff, opening files, printing to files... }

Notice that now I call "die" instead of "diealarm". Will this avoid the unsafe signals problem? Is there anyother workaround for the problem? I've searched the web and the Monastery, but keep being sure about the problems that my code can cause.

Thanks in advance for your cooperation and, as always, excuse my poor English.


In reply to Unsafe signals? by deibyz

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.