- my @in = ();
- for my $dir ('_IN', '_OUT') {
- push @in, map dbh->quote("$_$dir"), @serviceids;
- }
- my $in = join(',', @in);
-
- my $ssql = "
- $sql AND EXISTS (
- SELECT 1 FROM srvexport AS other
- WHERE other.serviceid IN ($in)
- AND srvexport.srv_date = other.srv_date
- AND ABS( $_date - $other_date ) <= 60
- )
- ";
-
- $ssql .= " AND srv_date >= '". $torrus_srvderive->last_srv_date. "' "
- if $torrus_srvderive->last_srv_date;
-
- $ssql .= $orderlimit;
-
- warn "searching for times to add $serviceid\n" if $DEBUG;
- warn $ssql if $DEBUG > 2;
- my $sth = dbh->prepare($ssql) or die $DBI::errstr; #better recovery here?
-
- warn "executing search\n" if $DEBUG;
-
- eval {
- my $h = set_sig_handler(
- 'ALRM', sub {
- local $SIG{__DIE__};
- warn "search timed out\n";
- dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"})
- if driver_name eq 'mysql';
- die '_timeout';
- },
- { mask=>['ALRM'] , safe=>1 }
- );
- alarm(5*60); # 15*60);
- $sth->execute($serviceid, $serviceid) or die $sth->errstr;
- alarm(0);
- };
- alarm(0);
- if ( $@ =~ /^_timeout/ ) {
- warn "search timed out; reconnecting and restarting\n";
- adminsuidsetup($user);
- next MAIN;
- } elsif ( $@ ) {
- die $@;
- }
+ warn "calling native srvderive: ". join(' ', @cmd). "\n" if $DEBUG;
+ my $out_and_err = '';
+ run( \@cmd, '>&', \$out_and_err ) #verbose? timeout?
+ or die "error calling native srvderive: $out_and_err\n";