Blocking Call kein Start der $finishFn

Begonnen von CoolTux, 24 September 2016, 11:49:29

Vorheriges Thema - Nächstes Thema

CoolTux

Ich habe mir eine kleine 99_myUtils geschrieben.


package main;

use strict;
use warnings;
use POSIX;
use Blocking;



sub myUtils_SystemCommands_Initialize($$) {

  my ($hash) = @_;

}

sub systemCommand($$) {

    my ($name,$command) = @_;
    my $hash = $defs{$name};
   
    Log3 $name, 3, "(Sub systemCommand - $name) - Starte Subroutine systemCommand";
   
   
    if( lc $name eq 'notifyreconnectinternetlost'
    || lc $name eq 'notifyfirewallsshinet'
    || lc $name eq 'notifypresencelocationmarko'
    || lc $name eq 'none') {
       
        BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));

        $hash->{helper}{RUNNING_PID} = BlockingCall("systemCommand_Run", $name."|".$command, "systemCommand_Done", 60, "systemCommand_Aborted", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
        Log3 $name, 3, "(Sub systemCommand - $name) - Starte Blocking Call";
    }
}

sub systemCommand_Run($) {

    my ($string) = @_;
    my ( $name, $command ) = split("\\|", $string);
    my $state;
   
    Log3 $name, 3, "(Sub systemCommand - $name) - Führe Systemkommando im nonBlocking Mode aus: $command";
   
   
    #####################################
    ### Wlan0 auf proxy01 #####
    if( $name eq "notifyReconnectInternetLost" ) {
        Log3 $name, 3, "(Sub systemCommand - $name) - Starte notifyReconnectInternetLost";
       
        if( $command eq "inet up" ) {
            $state = qx(ssh proxy01 'sudo /sbin/ifup wlan0');
            Log3 $name, 3, "(Sub systemCommand - $name) - wlan0 wird gestartet";
        }
   
        elsif ( $command eq "inet down" ) {
            $state = qx(ssh proxy01 'sudo /sbin/ifdown wlan0');
            Log3 $name, 3, "(Sub systemCommand - $name) - wlan0 wird beendet";
        }
   
        elsif ( $command eq "inet reconnect" ) {
            qx(ssh proxy01 'sudo /sbin/ifdown wlan0');
            sleep(2);
            $state = qx(ssh proxy01 'sudo /sbin/ifup wlan0');
            Log3 $name, 3, "(Sub systemCommand - $name) - wlan0 wird neu gestartet";
        }
    }
   
    #######################################
    #### Firewall Skripte auf proxy01 ###
    elsif( $name eq "notifyFirewallSshInet" ) {
        Log3 $name, 3, "(Sub systemCommand - $name) - Starte notifyFirewallSshInet";
       
        if ( $command eq "erlaubt" ) {
       
            $state = qx(ssh proxy01 'sudo /etc/iptables/rules.scripts/ssh_inbound_inet.sh allow');
            Log3 $name, 3, "(Sub systemCommand - $name) - Zugriff auf SSH übers Internet wird erlaubt";
        }
   
        elsif ( $command eq "verboten" ) {
       
            $state = qx(ssh proxy01 'sudo /etc/iptables/rules.scripts/ssh_inbound_inet.sh deny');
            Log3 $name, 3, "(Sub systemCommand - $name) - Zugriff auf SSH übers Internet wird verboten";
        }
    }
   
    elsif( $name eq "notifyPresenceLocationMarko" ) {
        Log3 $name, 3, "(Sub systemCommand - $name) - Starte notifyPresenceLocationMarko";
       
        if ( $command eq "gtagbattery" ) {
       
            $state = qx(gatttool -b 7C:2F:80:AA:5E:28 --char-read --handle=0x001b);
            Log3 $name, 3, "(Sub systemCommand - $name) - Rufe Batteriestatus vom GTag ab";
        }
   
    }
   
   
    #################################################
    #### Weiterverarbeitung der Rückgabewerte ######
    Log3 $name, 3, "(Sub systemCommand - $name) - Rückgabe an Auswertungsprogramm beginnt Name: $name, Command: $command, State: $state";
    return "$name|$command|$state";
}

sub systemCommand_Done($) {

    printf "Starte in die systemCommand_Done Routine";
    my ($string) = @_;
    my @a = split("\\|",$string);
    my $hash = $defs{$a[0]};
    my $name = $hash->{NAME};
    my $command = $a[1];
    my $state = $a[2];
   
    Log3 $name, 3, "(Sub systemCommand - $name) - Starte Verarbeitung im Rückgabeprogramm";
   
   
    delete($hash->{helper}{RUNNING_PID});
   
    Log3 $name, 3, "(Sub systemCommand - $name) - Der Helper ist diabled. Daher wird hier abgebrochen" if($hash->{helper}{DISABLED});
    return if($hash->{helper}{DISABLED});
   
    Log3 $name, 3, "(Sub systemCommand - $name) - Abschluss vom Systemkommando Aufruf im nonBlocking Mode. State gleich $state und command $command";
   
   
   
    if( $name eq "buttonSshInetFWstatus" ) {
        fhem "set buttonSshInetFWstatus fehler" if(! $state);
    }
       
}

sub systemCommand_Aborted($) {

    my ($hash) = @_;
    my $name = $hash->{NAME};

    delete($hash->{helper}{RUNNING_PID});
    Log3 $name, 3, "($name) - The BlockingCall Process terminated unexpectedly. Timedout";

}
1;


Aufrufen lasse ich die Funktion aus Notifys heraus, in diesen Notify Devices speichere ich auch die Hashreferenz.
Leider ist es so das Egal wie ich es mache die $finishFn nicht aufgerufen wird.
Die $blockingFn läuft wunderbar bin zum Ende durch.


In den Notify steht dann unter Helper

Helper:
     Running_pid:
       abortFn    systemCommand_Aborted
       arg        notifyPresenceLocationMarko|gtagbattery
       bc_pid     57
       finishFn   systemCommand_Done
       fn         systemCommand_Run
       pid        DEAD:3848
       timeout    60
       Abortarg:


Hat da vielleicht jemand eine Idee wo mein Unwissen steckt?




Grüße
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

DS_Starter

Hallo,

dieses Verhalten ist typisch wenn die Fn keinen Einzeiler zurückgibt.
Wenn das Ergebnis der Fn nicht nur eine Zeile enthält könntest du es mit encode versuchen.
Schau mal in meine 93_DbRep.pm, dort mache ich das sehr oft.
Sieht etwa so aus:


# Daten müssen als Einzeiler zurückgegeben werden
$arrstr = encode_base64($arrstr,"");

Log3 ($name, 4, "DbRep $name -> BlockingCall averval_DoParse finished");

return "$name|$arrstr|$device|$reading|$rt|0";


Vielleicht hilft es weiter.

Grüße,
Heiko
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

CoolTux

Hallo Heiko,

Vielen Dank. Das wäre in der Tat eine Erklärung für das Verhalten. Ich werde das heute Abend mal in Ruhe Testen.



Grüße
Leon
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

CoolTux

#3
Hallo Heiko,

Du liegst Gold richtig mit Deiner Vermutung.
Bei mir hat sich immer ein Zeilenumbruch mit eingeschlichen


2016.09.24 11:04:15 3: (Sub systemCommand - notifyPresenceLocationMarko) - Rückgabe an Auswertungsprogramm beginnt Name: notifyPresenceLocationMarko, Command: gtagbattery, State: Characteristic value/descriptor: 64

2016.09.24 11:05:25 3: HOMBOT (Roberta) - Connecting Problem, will check Luigi HTTP Server


Ich denke mal das ist es. Muss den jetzt nur irgendwie raus bekommen.


Grüße
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

DS_Starter

Prima, dann hat der Fehler fast schon verloren  :)

Grüße,
Heiko
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

CoolTux

Prima ich konnte es testen. Es liegt in der Tat daran. Deine Idee mit encode_base64 klappt super.

Vielen Dank noch mal.



Grüße
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

DS_Starter

#6
 :)
Allerdings ist die idee mit encode nicht von mir sondern aus dem Wiki:
http://www.fhemwiki.de/wiki/Blocking_Call#R.C3.BCckgabewerte_des_BlockingCalls_nur_als_Einzeiler-String

Ich verwende es nur sehr oft weil ich selbst genügend über dieses Problem gestolpert war bzw. immer wieder stolpere  ;)

Grüße,
Heiko
Proxmox+Debian+MariaDB, PV: SMA, Victron MPII+Pylontech+CerboGX
Maintainer: SSCam, SSChatBot, SSCal, SSFile, DbLog/DbRep, Log2Syslog, SolarForecast,Watches, Dashboard, PylonLowVoltage
Kaffeekasse: https://www.paypal.me/HMaaz
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/DS_Starter

CoolTux

Oh man bin ich ein Honk,

Ich habe diesen blöden Eintrag bestimmt 6 mal gelesen, denkst ich habe verstanden das dieser Tip mit meinem Problem zu tun haben könnte. Typisch ich.


Danke Dir
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net