2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 22:56:34 +00:00

fhem.pl: add fhemFork (from Blocking.pm), use POSIX::exit() for plotFork in fhem.pl (Forum #35261)

git-svn-id: https://svn.fhem.de/fhem/trunk@8265 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-03-22 13:58:15 +00:00
parent 396f6ba24a
commit 2e48c37976
3 changed files with 42 additions and 26 deletions

View File

@ -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});
}
###########################

View File

@ -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";

View File

@ -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;