deibyz has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unsafe signals?
by dave_the_m (Monsignor) on Feb 23, 2005 at 15:44 UTC | |
by cazz (Pilgrim) on Feb 23, 2005 at 17:09 UTC | |
|
Re: Unsafe signals?
by Tanktalus (Canon) on Feb 23, 2005 at 17:46 UTC |