From 4b45413b3ff0f2c51df6ee5484669498f70a2d1b Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sun, 5 Oct 2014 07:42:43 +0000 Subject: [PATCH] fhem.pl: add stacktrace for warnging. By Dietmar63, modified. (Forum #27471) git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@6684 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/fhem.pl | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index acac648cc..2391476da 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -2553,7 +2553,6 @@ InternalTimer($$$$) $nextat = $tim if(!$nextat || $nextat > $tim); } -##################################### sub RemoveInternalTimer($) { @@ -2564,20 +2563,46 @@ RemoveInternalTimer($) } ##################################### +sub +stacktrace() { + + my $i = 1; + my $max_depth = 50; + + Log 3, "stacktrace:"; + while( (my @call_details = (caller($i++))) && ($i<$max_depth) ) { + Log 3, sprintf (" %-35s called by %s (%s)", + $call_details[3], $call_details[1], $call_details[2]); + } +} + +my $inWarnSub; + sub SignalHandling() { if($^O ne "MSWin32") { - $SIG{'INT'} = sub { $sig_term = 1; }; - $SIG{'TERM'} = sub { $sig_term = 1; }; - $SIG{'PIPE'} = 'IGNORE'; - $SIG{'CHLD'} = 'IGNORE'; - $SIG{'HUP'} = sub { CommandRereadCfg(undef, "") }; - $SIG{'ALRM'} = sub { Log 1, "ALARM signal, blocking write?" }; + $SIG{INT} = sub { $sig_term = 1; }; + $SIG{TERM} = sub { $sig_term = 1; }; + $SIG{PIPE} = 'IGNORE'; + $SIG{CHLD} = 'IGNORE'; + $SIG{HUP} = sub { CommandRereadCfg(undef, "") }; + $SIG{ALRM} = sub { Log 1, "ALARM signal, blocking write?" }; #$SIG{'XFSZ'} = sub { Log 1, "XFSZ signal" }; # to test with limit filesize } + $SIG{__WARN__} = sub { + my ($msg) = @_; + + return if($inWarnSub); + $inWarnSub = 1; + chomp($msg); + Log 1, "PERL WARNING: $msg"; + stacktrace() if($attr{global}{verbose} >= 3 && $msg !~ m/ redefined at /); + $inWarnSub = 0; + }; } + ##################################### sub TimeNow()