From 89fa15c25ed4d9a80d430fd61fa0e3207803d119 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Tue, 22 Aug 2017 14:34:02 +0000 Subject: [PATCH] fhem.pl: cleaner code for HUP (Forum #75408) git-svn-id: https://svn.fhem.de/fhem/trunk@14944 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/fhem.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 7d6d47932..0645d4c25 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -257,7 +257,7 @@ my $logopened = 0; # logfile opened or using stdout my $namedef = "where is a single device name, a list separated by komma (,) or a regexp. See the devspec section in the commandref.html for details.\n"; my $rcvdquit; # Used for quit handling in init files my $readingsUpdateDelayTrigger; # needed internally -my $sig_term = 0; # if set to 1, terminate (saving the state) +my $gotSig; # non-undef if got a signal my $wbName = ".WRITEBUFFER"; # Buffer-name for delayed writing via select my %comments; # Comments from the include files my %duplicate; # Pool of received msg for multi-fhz/cul setups @@ -618,6 +618,7 @@ sub MAIN {MAIN:}; #Dummy my $errcount= 0; +$gotSig = undef if($gotSig && $gotSig eq "HUP"); while (1) { my ($rout,$rin, $wout,$win, $eout,$ein) = ('','', '','', '',''); @@ -642,7 +643,11 @@ while (1) { my $nfound = select($rout=$rin, $wout=$win, $eout=$ein, $timeout); $winService->{serviceCheck}->() if($winService->{serviceCheck}); - CommandShutdown(undef, undef) if($sig_term); + if($gotSig) { + CommandShutdown(undef, undef) if($gotSig eq "TERM"); + CommandRereadCfg(undef, "") if($gotSig eq "HUP"); + $gotSig = undef; + } if($nfound < 0) { my $err = int($!); @@ -3105,10 +3110,10 @@ sub SignalHandling() { if($^O ne "MSWin32") { - $SIG{TERM} = sub { $sig_term = 1; }; + $SIG{TERM} = sub { $gotSig = "TERM"; }; $SIG{PIPE} = 'IGNORE'; $SIG{CHLD} = 'IGNORE'; - $SIG{HUP} = sub { CommandRereadCfg(undef, "") }; + $SIG{HUP} = sub { $gotSig = "HUP"; }; $SIG{ALRM} = sub { Log 1, "ALARM signal, blocking write?" }; #$SIG{'XFSZ'} = sub { Log 1, "XFSZ signal" }; # to test with limit filesize }