X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCron.pm;h=c88ad1d3142d413dd87cb41d2c12f855eecb57dd;hb=23cadfcd0cfe94855905545e2d68c8c0c8981f02;hp=507a6a12a81053d9de0e6f136da6381beb73cce6;hpb=678715c76fa49f08acb30df0760b34407f49675c;p=spider.git diff --git a/perl/DXCron.pm b/perl/DXCron.pm index 507a6a12..c88ad1d3 100644 --- a/perl/DXCron.pm +++ b/perl/DXCron.pm @@ -12,8 +12,7 @@ use DXVars; use DXUtil; use DXM; use DXDebug; -use FileHandle; -use Carp; +use IO::File; use strict; @@ -58,7 +57,7 @@ sub init sub cread { my $fn = shift; - my $fh = new FileHandle; + my $fh = new IO::File; my $line = 0; dbg('cron', "cron: reading $fn\n"); @@ -216,47 +215,16 @@ sub last_connect # disconnect a locally connected thing sub disconnect { - my $call = uc shift; - my $dxchan = DXChannel->get($call); - if ($dxchan) { - if ($dxchan->is_ak1a) { - $dxchan->send_now("D", DXProt::pc39($main::mycall, "$main::mycall DXCron")); - } else { - $dxchan->send_now('D', ""); - } - $dxchan->disconnect; - } + my $call = shift; + run_cmd("disconnect $call"); } # start a connect process off sub start_connect { - my $call = uc shift; - my $lccall = lc $call; - - my $prog = "$main::root/local/client.pl"; - $prog = "$main::root/perl/client.pl" if ! -e $prog; - - my $pid = fork(); - if (defined $pid) { - if (!$pid) { - # in child, unset warnings, disable debugging and general clean up from us - $^W = 0; - eval "{ package DB; sub DB {} }"; - $SIG{HUP} = 'IGNORE'; - alarm(0); - DXChannel::closeall(); - $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT'; - exec $prog, $call, 'connect'; - dbg('cron', "exec '$prog' failed $!"); - } - dbg('cron', "connect to $call started"); - } else { - dbg('cron', "can't fork for $prog $!"); - } - - # coordinate - sleep(1); + my $call = shift; + # connecting is now done in one place - Yeah! + run_cmd("connect $call"); } # spawn any old job off @@ -270,12 +238,16 @@ sub spawn # in child, unset warnings, disable debugging and general clean up from us $^W = 0; eval "{ package DB; sub DB {} }"; - $SIG{HUP} = 'IGNORE'; - alarm(0); DXChannel::closeall(); - $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT'; - exec "$line"; - dbg('cron', "exec '$line' failed $!"); + for (@main::listeners) { + $_->close_server; + } + unless ($main::is_win) { + $SIG{HUP} = 'IGNORE'; + $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT'; + alarm(0); + } + exec "$line" or dbg('cron', "exec '$line' failed $!"); } dbg('cron', "spawn of $line started"); } else { @@ -297,7 +269,18 @@ sub rcmd return if !$noderef || !$noderef->pcversion; # send it - DXProt::addrcmd($main::mycall, $call, $line); + DXProt::addrcmd($DXProt::me, $call, $line); +} + +sub run_cmd +{ + my $line = shift; + my @in = DXCommandmode::run_cmd($DXProt::me, $line); + dbg('cron', "cmd run: $line"); + for (@in) { + s/\s*$//og; + dbg('cron', "cmd out: $_"); + } } 1; __END__