-
- my $pid = fork();
- if (defined $pid) {
- if (!$pid) {
- # in child, unset warnings, disable debugging and general clean up from us
- $^W = 0;
-# do "$main::root/perl/Disable_debug.pl";
- eval "{ package DB; sub DB {} }";
- alarm(0);
- $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT';
- exec "$line";
- dbg('cron', "exec '$line' failed $!");
- }
- dbg('cron', "spawn of $line started");
- } else {
- dbg('cron', "can't fork for $line $!");
+ my $t0 = [gettimeofday];
+
+ dbg("DXCron::spawn: $line") if isdbg("cron");
+ my $fc = DXSubprocess->new();
+ $fc->run(
+ sub {
+ my @res = `$line`;
+# diffms("DXCron spawn 1", $line, $t0, scalar @res) if isdbg('chan');
+ return @res
+ },
+ sub {
+ my ($fc, $err, @res) = @_;
+ if ($err) {
+ my $s = "DXCron::spawn: error $err";
+ dbg($s);
+ return;
+ }
+ for (@res) {
+ chomp;
+ dbg("DXCron::spawn: $_") if isdbg("cron");
+ }
+ diffms("by DXCron::spawn", $line, $t0, scalar @res) if isdbg('progress');
+ }
+ );
+}
+
+sub spawn_cmd
+{
+ my $line = shift;
+ my $t0 = [gettimeofday];
+
+ dbg("DXCron::spawn_cmd run: $line") if isdbg('cron');
+ my $fc = DXSubprocess->new();
+ $fc->run(
+ sub {
+ ++$main::me->{_nospawn};
+ my @res = $main::me->run_cmd($line);
+# diffms("DXCron spawn_cmd 1", $line, $t0, scalar @res) if isdbg('chan');
+ return @res;
+ },
+ sub {
+ my ($fc, $err, @res) = @_;
+ --$main::me->{_nospawn};
+ delete $main::me->{_nospawn} if exists $main::me->{_nospawn} && $main::me->{_nospawn} <= 0;
+ if ($err) {
+ my $s = "DXCron::spawn_cmd: error $err";
+ dbg($s);
+ }
+ for (@res) {
+ chomp;
+ dbg("DXCron::spawn_cmd: $_") if isdbg("cron");
+ }
+ diffms("by DXCron::spawn_cmd", $line, $t0, scalar @res) if isdbg('progress');
+ }
+ );
+}
+
+# do an rcmd to another cluster from the crontab
+sub rcmd
+{
+ my $call = uc shift;
+ my $line = shift;
+
+ # can we see it? Is it a node?
+ my $noderef = Route::Node::get($call);
+ return unless $noderef && $noderef->version;
+
+ # send it
+ DXProt::addrcmd($main::me, $call, $line);
+}
+
+sub run_cmd
+{
+ my $line = shift;
+ dbg("DXCron::run_cmd: $line") if isdbg('cron');
+ my @in = $main::me->run_cmd($line);
+ for (@in) {
+ s/\s*$//;
+ dbg("DXCron::cmd out: $_") if isdbg('cron');