From ea0118d445ec99e4509e8b68a9db8a9c5d13e370 Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Mon, 26 Dec 2022 22:09:18 +0100 Subject: [PATCH] cmd now prepends exec to command; pipes get closed --- web/clitools/crawler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/clitools/crawler.php b/web/clitools/crawler.php index f669363..9c40120 100755 --- a/web/clitools/crawler.php +++ b/web/clitools/crawler.php @@ -243,7 +243,7 @@ if ($restore) { $host=$insts[$buf[$i]+0]; eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N); $descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; - $procs[]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes), 'instk'=>$buf[$i]+0, 'host'=>$host, 'begts'=>microtime(true)]; + $procs[]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes[]), 'instk'=>$buf[$i]+0, 'host'=>$host, 'begts'=>microtime(true)]; } eecho(1,'restored previous session.'.N); } else { @@ -315,7 +315,7 @@ if ($restore) { $host=$insts[$instk]; eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N); $descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; - $procs[]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes), 'instk'=>$instk, 'host'=>$host, 'begts'=>microtime(true)]; + $procs[]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes[]), 'instk'=>$instk, 'host'=>$host, 'begts'=>microtime(true)]; } $instk--; @@ -329,16 +329,18 @@ do { eecho(0,'[[[ CHECKING PROCESSES POOL ]]]'.N); $somerun=false; foreach ($procs as $key=>$proc) { - if (!is_null($proc)) { + if (!is_null($proc) && is_resource($proc['proc'])) { $pstat=proc_get_status($proc['proc']); if (!$pstat['running']) { + fclose($pipes[$key][0]); + fclose($pipes[$key][1]); $done++; $out='proc slot '.$key.': finished running on «'.$proc['host'].'» (exit code: '.$pstat['exitcode'].')'; if ($instk<$cinsts-1) { $instk++; $host=$insts[$instk]; $descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; - $procs[$key]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes), 'instk'=>$instk, 'host'=>$host, 'begts'=>$now]; + $procs[$key]=['proc'=>proc_open(cmd($childopts,$host),$descspecs,$pipes[$key]), 'instk'=>$instk, 'host'=>$host, 'begts'=>$now]; $out.='; started a new process on «'.$host.'».'.N; } else { $out.='; no more hosts to check.'.N; @@ -383,7 +385,7 @@ function writestatus(&$statusjfp,&$opts,&$instk,&$tet,&$done,&$procs) { } function cmd(&$childopts, &$host) { - return(__DIR__.'/'.CHILD.$childopts.' '.escapeshellarg($host)); + return('exec '.__DIR__.'/'.CHILD.$childopts.' '.escapeshellarg($host)); } function eecho($lev,$msg) {