X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCron.pm;h=d300779456931861463060bf80ed80779cb5bc58;hb=85b6ea316f8da5cb0a9fe716bbb5cd17bd2f5fdb;hp=507a6a12a81053d9de0e6f136da6381beb73cce6;hpb=678715c76fa49f08acb30df0760b34407f49675c;p=spider.git diff --git a/perl/DXCron.pm b/perl/DXCron.pm index 507a6a12..d3007794 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"); @@ -226,6 +225,13 @@ sub disconnect } $dxchan->disconnect; } + my $out = grep {$_->{call} eq $call} @main::outstanding_connects; + if ($out) { + unless ($^O =~ /^MS/i) { + kill 'TERM', $out->{pid}; + } + @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects; + } } # start a connect process off @@ -234,29 +240,15 @@ 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"); + if (grep {$_->{call} eq $call} @main::outstanding_connects) { + dbg('cron', "Connect not started, outstanding connect to $call"); + return; + } + if (-e "$main::root/connect/$lccall") { + ExtMsg::start_connect($call, "$main::root/connect/$lccall"); } else { - dbg('cron', "can't fork for $prog $!"); + dbg('err', "Cannot find connect script for $lccall"); } - - # coordinate - sleep(1); } # spawn any old job off @@ -270,12 +262,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 ($^O =~ /^MS/) { + $SIG{HUP} = 'IGNORE'; + $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT'; + } + exec "$line" or dbg('cron', "exec '$line' failed $!"); } dbg('cron', "spawn of $line started"); } else { @@ -297,7 +293,7 @@ sub rcmd return if !$noderef || !$noderef->pcversion; # send it - DXProt::addrcmd($main::mycall, $call, $line); + DXProt::addrcmd($DXProt::me, $call, $line); } 1; __END__