diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 87a719b12..6c24afbfd 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -400,7 +400,7 @@ FW_Read($) # Process SVG rendering as a parallel process my $p = $data{FWEXT}; if(grep { $p->{$_}{FORKABLE} && $arg =~ m+^$FW_ME$_+ } keys %{$p}) { - my $pid = fork(); + my $pid = fhemFork(); if($pid) { # success, parent use constant PRIO_PROCESS => 0; setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf); @@ -424,7 +424,7 @@ FW_Read($) my $cacheable = FW_answerCall($arg); if($cacheable == -1){ # Longpoll / inform request; - exit if($hash->{isChild}); + POSIX::exit(0) if($hash->{isChild}); return; } @@ -455,7 +455,7 @@ FW_Read($) delete($defs{$name}); } - exit if($hash->{isChild}); + POSIX::exit(0) if($hash->{isChild}); } sub @@ -469,7 +469,7 @@ FW_closeConn($) TcpServer_Close($hash); delete($defs{$hash->{NAME}}); } - exit if($hash->{isChild}); + POSIX::exit(0) if($hash->{isChild}); } ########################### diff --git a/fhem/FHEM/Blocking.pm b/fhem/FHEM/Blocking.pm index 54ac2fd5a..17240aa00 100644 --- a/fhem/FHEM/Blocking.pm +++ b/fhem/FHEM/Blocking.pm @@ -67,7 +67,7 @@ BlockingCall($$@) } # do fork - my $pid = fork; + my $pid = fhemFork; if(!defined($pid)) { Log 1, "Cannot fork: $!"; return undef; @@ -84,20 +84,6 @@ BlockingCall($$@) } # Child here - - # Close all kind of FD. Reasons: - # - cannot restart FHEM if child keeps TCP Serverports open - # ...? - foreach my $d (sort keys %defs) { - my $h = $defs{$d}; - $h->{DBH}->{InactiveDestroy} = 1 if($h->{TYPE} eq 'DbLog'); - TcpServer_Close($h) if($h->{SERVERSOCKET}); - if($h->{DeviceName}) { - require "$attr{global}{modpath}/FHEM/DevIo.pm"; - DevIo_CloseDev($h,1); - } - } - no strict "refs"; my $ret = &{$blockingFn}($arg); use strict "refs"; diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 10fe960fd..253eba916 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -3810,14 +3810,17 @@ readingsSingleUpdate($$$$) ############################################################################## sub -fhemTzOffset($) { - # see http://stackoverflow.com/questions/2143528/whats-the-best-way-to-get-the-utc-offset-in-perl - my $t = shift; - my @l = localtime($t); - my @g = gmtime($t); +fhemTzOffset($) +{ + # see http://stackoverflow.com/questions/2143528/whats-the-best-way-to-get-the-utc-offset-in-perl + my $t = shift; + my @l = localtime($t); + my @g = gmtime($t); - # the offset is positive if the local timezone is ahead of GMT, e.g. we get 2*3600 seconds for CET DST vs GMT - return 60*(($l[2] - $g[2] + ((($l[5]<<9)|$l[7]) <=> (($g[5]<<9)|$g[7])) * 24) * 60 + $l[1] - $g[1]); + # the offset is positive if the local timezone is ahead of GMT, e.g. we get + # 2*3600 seconds for CET DST vs GMT + return 60*(($l[2] - $g[2] + ((($l[5]<<9)|$l[7]) <=> (($g[5]<<9)|$g[7])) * 24)* + 60 + $l[1] - $g[1]); } sub @@ -4133,4 +4136,31 @@ addStructChange($$$) push @structChangeHist, "$cmd $param"; } +sub +fhemFork() +{ + my $pid = fork; + if(!defined($pid)) { + Log 1, "Cannot fork: $!"; + return undef; + } + + return $pid if($pid); + + # Child here + # Close all kind of FD. Reasons: + # - cannot restart FHEM if child keeps TCP Serverports open + # ...? + foreach my $d (sort keys %defs) { + my $h = $defs{$d}; + $h->{DBH}->{InactiveDestroy} = 1 if($h->{TYPE} eq 'DbLog'); + TcpServer_Close($h) if($h->{SERVERSOCKET}); + if($h->{DeviceName}) { + require "$attr{global}{modpath}/FHEM/DevIo.pm"; + DevIo_CloseDev($h,1); + } + } + return 0; +} + 1;