X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=d5271313960a1f6f42f6142a883923aa7e9afabd;hb=772dc67533220a11f5ff6962abff8ea46d247ece;hp=cbba3b79210bf5ebfa0a77f8377ad57ff80816a6;hpb=0de1a272bd43c887020d9e03a4f56f44ab4bb080;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index cbba3b79..d5271313 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -43,7 +43,7 @@ use JSON; use Time::HiRes qw(gettimeofday tv_interval); use Mojo::IOLoop; -use Mojo::IOLoop::ForkCall; +use Mojo::IOLoop::Subprocess; use Mojo::UserAgent; use strict; @@ -490,7 +490,7 @@ sub send_ans } # -# this is the thing that runs the command, it is done like this for the +# this is the thing that preps for running the command, it is done like this for the # benefit of remote command execution # @@ -1309,28 +1309,40 @@ sub spawn_cmd my $t0 = [gettimeofday]; no strict 'refs'; - - my $fc = Mojo::IOLoop::ForkCall->new; - $fc->serializer(\&encode_json); - $fc->deserializer(\&decode_json); + + # just behave normally if something has set the "one-shot" _nospawn in the channel + return ($cmdref->(@$args)) if $self->{_nospawn}; + + my $fc = Mojo::IOLoop::Subprocess->new; +# $fc->serializer(\&encode_json); +# $fc->deserializer(\&decode_json); $fc->run( - sub {my @args = @_; my @res = $cmdref->(@args); return @res}, - $args, + sub { + my $subpro = shift; + if (isdbg('spawn_cmd')) { + my $s = "line: $line"; + $s .= ", args: " . join(', ', @$args) if $args && @$args; + } + my @res = $cmdref->(@$args); + return @res; + }, +# $args, sub { my ($fc, $err, @res) = @_; my $dxchan = DXChannel::get($call); return unless $dxchan; - if (defined $err) { + if ($err) { my $s = "DXCommand::spawn_cmd: call $call error $err"; dbg($s) if isdbg('chan'); $dxchan->send($s); return; } if ($cb) { - $cb->($dxchan, @res); - } else { - return unless @res; + # transform output if required + @res = $cb->($dxchan, @res); + } + if (@res) { if (defined $prefix) { $dxchan->send(map {"$prefix$_"} @res); } else {