mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: evaluate the FHEM_GLOBALATTR environment variable (Forum #99944).
git-svn-id: https://svn.fhem.de/fhem/trunk@19328 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c9bba8477d
commit
0f32241086
@ -177,7 +177,17 @@ telnet) or single client command (via fhem.pl). Example:
|
||||
</ul>
|
||||
<br>
|
||||
If a OS-user called fhem exists, and FHEM is started as root, FHEM will
|
||||
automatically change to to this user via setuid. <br>
|
||||
automatically change to to this user via setuid.
|
||||
<br><br>
|
||||
|
||||
If FHEM is started with the -d option (perl fhem.pl -d fhem.cfg), then the
|
||||
verbose level is set to 5 and the logfile is redirected to the STDOUT.
|
||||
<br><br>
|
||||
|
||||
The environment variable FHEM_GLOBALATTR is evaluated: it consists of space
|
||||
separated name=value pairs, where name is a global attribute. Values from this
|
||||
source override values set in the configuration file.
|
||||
|
||||
</ul>
|
||||
<!-- intro end - diese Zeile nicht entfernen! -->
|
||||
|
||||
|
@ -158,7 +158,17 @@ Die Kommunikation mit FHEM kann entweder in einer "session" (über telnet) o
|
||||
</ul>
|
||||
<br>
|
||||
Falls FHEM als root gestartet wurde, und ein OS-Benutzer fhem existiert, dann
|
||||
wechselt FHEM nach dem start zu diesem Benutzer (via setuid). <br>
|
||||
wechselt FHEM nach dem start zu diesem Benutzer (via setuid).
|
||||
<br><br>
|
||||
|
||||
Falls FHEM mit der -d Koommandozeilenoption gestartet wurde (perl fhem.pl -d
|
||||
fhem.cfg), dann wird verbose auf 5 gesetzt und die Logs werden auf STDOUT
|
||||
geschrieben.
|
||||
<br><br>
|
||||
|
||||
Die Umgebungsvariable FHEM_GLOBALATTR wird ausgewertet: sie enthält
|
||||
Leerzeichengetrennte Name=Wert Paare, wobei Name ein global Attribut ist. So
|
||||
gesetzte Werte überschreiben die Werte aus der Konfigurationsdatei.
|
||||
</ul>
|
||||
<br>
|
||||
<!-- intro end - diese Zeile nicht entfernen! -->
|
||||
|
20
fhem/fhem.pl
20
fhem/fhem.pl
@ -111,6 +111,7 @@ sub WriteStatefile();
|
||||
sub XmlEscape($);
|
||||
sub addEvent($$);
|
||||
sub addToDevAttrList($$);
|
||||
sub applyGlobalAttrFromEnv();
|
||||
sub delFromDevAttrList($$);
|
||||
sub addToAttrList($);
|
||||
sub delFromAttrList($);
|
||||
@ -562,7 +563,9 @@ if(configDBUsed()) {
|
||||
# As newer Linux versions reset serial parameters after fork, we parse the
|
||||
# config file after the fork. But we need some global attr parameters before, so we
|
||||
# read them here.
|
||||
my (undef, $globalAttrFromEnv) = parseParams($ENV{FHEM_GLOBALATTR});
|
||||
setGlobalAttrBeforeFork($attr{global}{configfile});
|
||||
applyGlobalAttrFromEnv();
|
||||
|
||||
Log 1, $_ for eval{@{$winService->{ServiceLog}};};
|
||||
|
||||
@ -609,6 +612,7 @@ if(configDBUsed()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
applyGlobalAttrFromEnv();
|
||||
|
||||
my $pfn = $attr{global}{pidfilename};
|
||||
if($pfn) {
|
||||
@ -1481,6 +1485,7 @@ CommandRereadCfg($$)
|
||||
$ret = (defined($ret) ? "$ret\n$ret2" : $ret2) if(defined($ret2));
|
||||
}
|
||||
}
|
||||
applyGlobalAttrFromEnv();
|
||||
|
||||
$defs{$name} = $selectlist{$name} = $cl if($name && $name ne "__anonymous__");
|
||||
$inform{$name} = $informMe if($informMe);
|
||||
@ -2742,7 +2747,10 @@ GlobalAttr($$$$)
|
||||
return undef;
|
||||
}
|
||||
|
||||
return undef if($type ne "set");
|
||||
my $ev = $globalAttrFromEnv->{$name};
|
||||
return "$name is readonly, it is set in the FHEM_GLOBALATTR environment"
|
||||
if(defined($ev) && defined($val) && $ev ne $val);
|
||||
|
||||
################
|
||||
if($name eq "logfile") {
|
||||
my @t = localtime(gettimeofday());
|
||||
@ -5608,6 +5616,7 @@ parseParams($;$$$)
|
||||
$joiner = $separator if(!$joiner); # needed if separator is a regexp
|
||||
$keyvalueseparator = '=' if(!$keyvalueseparator);
|
||||
my(@a, %h);
|
||||
return(\@a, \%h) if(!defined($cmd));
|
||||
|
||||
my @params;
|
||||
if( ref($cmd) eq 'ARRAY' ) {
|
||||
@ -5925,4 +5934,13 @@ IsWe(;$$)
|
||||
return $we ? 1 : 0;
|
||||
}
|
||||
|
||||
sub
|
||||
applyGlobalAttrFromEnv()
|
||||
{
|
||||
while(my ($k,$v)= each %{$globalAttrFromEnv}) {
|
||||
Log 3, "From the FHEM_GLOBALATTR environment: attr global $k $v";
|
||||
CommandAttr(undef, "global $k $v");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user