Fix for $SIG{__DIE__} handler in MRTG_lib.pm

3 messages Options
Embed this post
Permalink
Steven Bakker () Fix for $SIG{__DIE__} handler in MRTG_lib.pm
Reply Threaded More More options
Print post
Permalink
Hi,

We ran into some trouble with MRTG combined with logging, where an
"eval{}" can trigger an "exit()". This is due to MRTG_lib.pm defining a
custom $SIG{__DIE__} handler, which also gets called in eval{} blocks.

Due to the way Debian packages are set up, SNMP_Session.pm is not
included in the "mrtg" package, but in a separate package
"libnsmp-session-perl". This is fine, if it weren't for the fact that it
is version 1.07, not 1.08 (which contains the fixed eval). Hence, we see
things like:

2008-03-20 01:17:02 -- Can't locate IO/Socket/INET6.pm in @INC (@INC  
contains: /usr/bin/../lib/mrtg2 /usr/bin /etc/perl /usr/local/lib/perl/
5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/
lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /usr/
share/perl5/SNMP_Session.pm line 139.

In any case, this points to a deeper problem: if any of the libraries
that MRTG pulls in does an eval{} that fails, you'll still be aborting
the program unexpectedly.

I'd suggest changing the die-handler code in MRTG_lib.pm to contain a
check for $^S (perldoc perlvar):

        $SIG{__DIE__} = sub {
                        return if $^S;
                       
                        ...
                };

This should also remove the need for all the localised $SIG{__DIE__}
statements.

Let me know if this makes sense.

Cheers,
Steven


oetiker () Re: Fix for $SIG{__DIE__} handler in MRTG_lib.pm
Reply Threaded More More options
Print post
Permalink
Hi Steve,

neat trick with $^S ... will add ... will leave the local SIG in
anyway since I read somewhere that it is not good to have a __SIG__
handler in eval anyway ...

you may want to log a bug versus the debian packet as well to get
the fix in there too before the next debian release :-)

note that SNMP_Session 1.12 addes the localized sighanders as well
...

cheers
tobi

Today Steven Bakker wrote:

> Hi,
>
> We ran into some trouble with MRTG combined with logging, where an
> "eval{}" can trigger an "exit()". This is due to MRTG_lib.pm defining a
> custom $SIG{__DIE__} handler, which also gets called in eval{} blocks.
>
> Due to the way Debian packages are set up, SNMP_Session.pm is not
> included in the "mrtg" package, but in a separate package
> "libnsmp-session-perl". This is fine, if it weren't for the fact that it
> is version 1.07, not 1.08 (which contains the fixed eval). Hence, we see
> things like:
>
> 2008-03-20 01:17:02 -- Can't locate IO/Socket/INET6.pm in @INC (@INC
> contains: /usr/bin/../lib/mrtg2 /usr/bin /etc/perl /usr/local/lib/perl/
> 5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/
> lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /usr/
> share/perl5/SNMP_Session.pm line 139.
>
> In any case, this points to a deeper problem: if any of the libraries
> that MRTG pulls in does an eval{} that fails, you'll still be aborting
> the program unexpectedly.
>
> I'd suggest changing the die-handler code in MRTG_lib.pm to contain a
> check for $^S (perldoc perlvar):
>
>         $SIG{__DIE__} = sub {
>                         return if $^S;
>
>                         ...
>                 };
>
> This should also remove the need for all the localised $SIG{__DIE__}
> statements.
>
> Let me know if this makes sense.
>
> Cheers,
> Steven
>
> _______________________________________________
> mrtg-developers mailing list
> [hidden email]
> https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers
>
>

--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten
http://it.oetiker.ch [hidden email] ++41 62 213 9902


Steven Bakker () Re: Fix for $SIG{__DIE__} handler in MRTG_lib.pm
Reply Threaded More More options
Print post
Permalink
On Thu, 2008-03-20 at 11:47 +0100, Tobias Oetiker wrote:

> neat trick with $^S ... will add ... will leave the local SIG in
> anyway since I read somewhere that it is not good to have a __SIG__
> handler in eval anyway ...

Yeah, better safe than sorry. ;-)

The "perlvar" man page also has something to say about the use of $^S
and $SIG{__DIE__}. They advise the use of an END{} block to catch a die,
but I doubt whether that is a good idea in this case. You typically
close down and clean up in an END{} block, not do object creation and
file opening. YMMV.

> you may want to log a bug versus the debian packet as well to get
> the fix in there too before the next debian release :-)
>
> note that SNMP_Session 1.12 addes the localized sighanders as well
> ...

Yes. In fact, it was already in 1.08 (AFAICS). Unfortunately, we have a
schizophrenic Debian install (it's still Sarge, but with tons of
backports). I'm pretty sure the "official" Debian repos contain versions
of SNMP_Session and MRTG that are properly synchronised.

Cheers,
Steven