cmd now prepends exec to command; pipes get closed

This commit is contained in:
pezcurrel 2022-12-26 22:09:18 +01:00
parent 463ef7cd37
commit ea0118d445

View file

@ -243,7 +243,7 @@ if ($restore) {
$host=$insts[$buf[$i]+0]; $host=$insts[$buf[$i]+0];
eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N); eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N);
$descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; $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); eecho(1,'restored previous session.'.N);
} else { } else {
@ -315,7 +315,7 @@ if ($restore) {
$host=$insts[$instk]; $host=$insts[$instk];
eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N); eecho(1,'bootstrapping processes pool, adding host «'.$host.'».'.N);
$descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; $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--; $instk--;
@ -329,16 +329,18 @@ do {
eecho(0,'[[[ CHECKING PROCESSES POOL ]]]'.N); eecho(0,'[[[ CHECKING PROCESSES POOL ]]]'.N);
$somerun=false; $somerun=false;
foreach ($procs as $key=>$proc) { foreach ($procs as $key=>$proc) {
if (!is_null($proc)) { if (!is_null($proc) && is_resource($proc['proc'])) {
$pstat=proc_get_status($proc['proc']); $pstat=proc_get_status($proc['proc']);
if (!$pstat['running']) { if (!$pstat['running']) {
fclose($pipes[$key][0]);
fclose($pipes[$key][1]);
$done++; $done++;
$out='proc slot '.$key.': finished running on «'.$proc['host'].'» (exit code: '.$pstat['exitcode'].')'; $out='proc slot '.$key.': finished running on «'.$proc['host'].'» (exit code: '.$pstat['exitcode'].')';
if ($instk<$cinsts-1) { if ($instk<$cinsts-1) {
$instk++; $instk++;
$host=$insts[$instk]; $host=$insts[$instk];
$descspecs=[ 0=>['pipe','r'], 1=>['pipe','w'], 2=>['file',$rundirpath.'/'.$host.'.stderr.log','w'] ]; $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; $out.='; started a new process on «'.$host.'».'.N;
} else { } else {
$out.='; no more hosts to check.'.N; $out.='; no more hosts to check.'.N;
@ -383,7 +385,7 @@ function writestatus(&$statusjfp,&$opts,&$instk,&$tet,&$done,&$procs) {
} }
function cmd(&$childopts, &$host) { function cmd(&$childopts, &$host) {
return(__DIR__.'/'.CHILD.$childopts.' '.escapeshellarg($host)); return('exec '.__DIR__.'/'.CHILD.$childopts.' '.escapeshellarg($host));
} }
function eecho($lev,$msg) { function eecho($lev,$msg) {