FHEM Forum

FHEM => Sonstiges => Thema gestartet von: Uli Zappe am 17 Juli 2016, 04:03:03

Titel: fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: Uli Zappe am 17 Juli 2016, 04:03:03
Hallo,

mit der aktuellen version von fhem.pl bekomme ich in der der FHEM-Logdatei (fhem-2016-07.log) immer wieder mal folgende Meldung:

2016.07.16 22:38:51 1: PERL WARNING: Use of uninitialized value $v in substitution (s///) at /usr/bin/fhem.pl line 992.
2016.07.16 22:38:51 1: PERL WARNING: Use of uninitialized value $v in concatenation (.) or string at /usr/bin/fhem.pl line 993.


Das Ganze passiert (fast?) ausschließlich, wenn (von einer Instanz von PRESENCE) eine in 99_myUtils.pm definierte Subroutine aufgerufen wird, bei der ein oder mehrere Parameter leere Strings ("") sind. Aber es passiert nicht immer, wenn diese Subroutine aufgerufen wird, sondern eben nur manchmal.

Ich habe keine Ahnung, ob und wie der Aufruf einer externen Perl-Subroutine in fhem.pl zu solch einem scheinbar undeterminierten internen Fehler führen könnte.

Funktionieren tut alles fehlerfrei, es gibt nur diese seltsame Warnung.
Titel: Antw:fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: rudolfkoenig am 17 Juli 2016, 10:08:48
Es geht um das Ausfuehren eines Perl-Ausdrucks (in FHEM ueblicherweise mit {} markiert), und dass dabei der Wert einer der zu setzenden Variablen ($NAME/$EVTPARTx/etc) nicht definiert ist.
Kannst du bitte "attr global stacktrace" und "attr global verbose 5" setzen, und das Log mit der Fehlermeldung hier anhaengen?
Titel: Antw:fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: Uli Zappe am 17 Juli 2016, 14:00:18
Zitat von: rudolfkoenig am 17 Juli 2016, 10:08:48
Es geht um das Ausfuehren eines Perl-Ausdrucks (in FHEM ueblicherweise mit {} markiert)
Yep, in meinem Fall ist das ein Perl-Ausdruck, der das powerCmd in einer PRESENCE-Instanz definiert:

define Projektor PRESENCE shellscript '/usr/local/bin/projector numstate' 1 1
attr Projektor devStateIcon present:on:off absent:off:on ON:on OFF:off
attr Projektor event-on-change-reading state
attr Projektor eventMap /power on:on/power off:off/
attr Projektor group Geräte
attr Projektor ping_count 1
attr Projektor powerCmd {powerCommand($NAME, "", $ARGUMENT, "projector", "", "", 1)}
attr Projektor room Abbey Road
attr Projektor sortby 1


Die Subroutine powerCommand (aus 99_myUtils.pm) lautet:

sub powerCommand($$$$$$$)
{
# arguments
my ($presenceName, $hostname, $action, $command, $onCommand, $offCommand, $guiFeedback) = @_;

# variables for building and executing the command
my $onCommandString;
my $offCommandString;
my $presenceState;
my $returnValue = "Internal error";

# variables for builing the success log message
my $successMessageOnCommandName;
my $successMessageOffCommandName;
my $successMessageDeviceName;
my $successMessage;

# sanity check
return "Configuration error: Either \$presenceName or \$hostname must be specified" if $presenceName eq "" && $hostname eq "";
return "Configuration error: Either \$command or \$onCommand and \$offCommand must be specified" if $command eq "" && ($onCommand eq "" || $offCommand eq "");

# initialize variables
$presenceName = $hostname if $presenceName eq "";
$presenceState = Value($presenceName);
$successMessageDeviceName = ($hostname eq "")? $presenceName : $hostname;

# build command strings and log message command names
# to be able to tell success from failure, stdout is ignored (= redirected to /dev/null), i.e. an empty return means success
# stderr is redirected to stdout so that error messages can be logged
if ($command eq "") # different commands for on and off
{
$successMessageOnCommandName = $onCommand;
$successMessageOffCommandName = $offCommand;
$onCommandString = "/usr/local/bin/$onCommand $hostname 2>&1 1>/dev/null";
$offCommandString = "/usr/local/bin/$offCommand $hostname 2>&1 1>/dev/null";
}
else # command command with on|off argument for on and off
{
$successMessageOnCommandName = $successMessageOffCommandName = $command;
$onCommandString = "/usr/local/bin/$command $hostname on 2>&1 1>/dev/null";
$offCommandString = "/usr/local/bin/$command $hostname off 2>&1 1>/dev/null";
}

# depending on $action argument, build log message success string and execute command
if ("$action" eq "on" && $presenceState eq "absent")
{
$successMessage = "$successMessageOnCommandName: Waking \"$successMessageDeviceName\"";
fhem("setreading $presenceName state ON") if $guiFeedback;
$returnValue = `$onCommandString`;
}
elsif ("$action" eq "off" && $presenceState eq "present")
{
$successMessage = "$successMessageOffCommandName: Putting \"$successMessageDeviceName\" to sleep";
fhem("setreading $presenceName state OFF") if $guiFeedback;
$returnValue = `$offCommandString`;
}
else {return 0;} # do nothing

# in case of success (= empty result string), log success message
Log 3, "PRESENCE ($presenceName) - $successMessage" if $returnValue eq "";

# return 0 (= success) or error message
return $returnValue;
}



/usr/local/bin/projector ist ein C-Binary, das einen Projektor ansteuert.

ZitatKannst du bitte "attr global stacktrace" und "attr global verbose 5" setzen, und das Log mit der Fehlermeldung hier anhängen?

Voilà. Ich hoffe, ich habe aus dem Datenwust den relevanten Abschnitt vollständig herausgefischt:

2016.07.17 13:42:32 4: Connection accepted from WEBphone_192.168.1.72_64066
2016.07.17 13:42:32 4: WEBphone_192.168.1.72_64066 POST /fhem?cmd.Projektor=set%20Projektor%20on&room=Abbey%20Road&room=Abbey%20Road&XHR=1&fw_id=654; BUFLEN:0
2016.07.17 13:42:32 5: Cmd: >set Projektor on<
2016.07.17 13:42:32 5: PRESENCE (Projektor) - executing powerCmd: {powerCommand($NAME, "", $ARGUMENT, "projector", "", "", 1)}
2016.07.17 13:42:32 5: Cmd: >{powerCommand($NAME, "", $ARGUMENT, "projector", "", "", 1)}<
2016.07.17 13:42:32 1: PERL WARNING: Use of uninitialized value $v in substitution (s///) at /usr/bin/fhem.pl line 992.
2016.07.17 13:42:32 3: stacktrace:
2016.07.17 13:42:32 3:     main::__ANON__                      called by /usr/bin/fhem.pl (992)
2016.07.17 13:42:32 3:     main::AnalyzePerlCommand            called by /usr/bin/fhem.pl (1020)
2016.07.17 13:42:32 3:     main::AnalyzeCommand                called by /usr/bin/fhem.pl (950)
2016.07.17 13:42:32 3:     main::AnalyzeCommandChain           called by /usr/share/fhem/FHEM/73_PRESENCE.pm (309)
2016.07.17 13:42:32 3:     main::PRESENCE_Set                  called by /usr/bin/fhem.pl (3194)
2016.07.17 13:42:32 3:     main::CallFn                        called by /usr/bin/fhem.pl (1596)
2016.07.17 13:42:32 3:     main::DoSet                         called by /usr/bin/fhem.pl (1628)
2016.07.17 13:42:32 3:     main::CommandSet                    called by /usr/bin/fhem.pl (1080)
2016.07.17 13:42:32 3:     main::AnalyzeCommand                called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (2244)
2016.07.17 13:42:32 3:     main::FW_fC                         called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (723)
2016.07.17 13:42:32 3:     main::FW_answerCall                 called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (454)
2016.07.17 13:42:32 3:     main::FW_Read                       called by /usr/bin/fhem.pl (3199)
2016.07.17 13:42:32 3:     main::CallFn                        called by /usr/bin/fhem.pl (667)
2016.07.17 13:42:32 1: PERL WARNING: Use of uninitialized value $v in concatenation (.) or string at /usr/bin/fhem.pl line 993.
2016.07.17 13:42:32 3: stacktrace:
2016.07.17 13:42:32 3:     main::__ANON__                      called by /usr/bin/fhem.pl (993)
2016.07.17 13:42:32 3:     main::AnalyzePerlCommand            called by /usr/bin/fhem.pl (1020)
2016.07.17 13:42:32 3:     main::AnalyzeCommand                called by /usr/bin/fhem.pl (950)
2016.07.17 13:42:32 3:     main::AnalyzeCommandChain           called by /usr/share/fhem/FHEM/73_PRESENCE.pm (309)
2016.07.17 13:42:32 3:     main::PRESENCE_Set                  called by /usr/bin/fhem.pl (3194)
2016.07.17 13:42:32 3:     main::CallFn                        called by /usr/bin/fhem.pl (1596)
2016.07.17 13:42:32 3:     main::DoSet                         called by /usr/bin/fhem.pl (1628)
2016.07.17 13:42:32 3:     main::CommandSet                    called by /usr/bin/fhem.pl (1080)
2016.07.17 13:42:32 3:     main::AnalyzeCommand                called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (2244)
2016.07.17 13:42:32 3:     main::FW_fC                         called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (723)
2016.07.17 13:42:32 3:     main::FW_answerCall                 called by /usr/share/fhem/FHEM/01_FHEMWEB.pm (454)
2016.07.17 13:42:32 3:     main::FW_Read                       called by /usr/bin/fhem.pl (3199)
2016.07.17 13:42:32 3:     main::CallFn                        called by /usr/bin/fhem.pl (667)
2016.07.17 13:42:32 5: Cmd: >setreading Projektor state ON<
2016.07.17 13:42:32 5: Triggering Projektor (1 changes)
2016.07.17 13:42:32 5: Starting notify loop for Projektor, first event ON
2016.07.17 13:42:32 3: PRESENCE (Projektor) - projector: Waking "Projektor"
Titel: Antw:fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: rudolfkoenig am 17 Juli 2016, 16:56:13
Wenn ich das richtig sehe, ist das ein PRESENCE Bug: im Fall von shellscript wird $hash->{ADDRESS} nicht gesetzt, aber als Variablenwert fuer powerCmd angeboten. Sollte dem PRESENCE Autor vorgelegt werden.
Titel: Antw:fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: Uli Zappe am 17 Juli 2016, 19:00:08
Zitat von: rudolfkoenig am 17 Juli 2016, 16:56:13
Sollte dem PRESENCE Autor vorgelegt werden.
OK, mach ich.
Titel: Antw:fhem.pl: PERL WARNING: Use of uninitialized value $v
Beitrag von: Markus Bloch am 17 Juli 2016, 20:18:55
Hallo zusammen,

habe ich soeben gefixt und eingecheckt.

Gruß
Markus