<?php
$lane=$argv[1]??'';$targets=['B'=>['pid'=>2356,'root'=>'/tmp/cdx-nutrition-ts8-B-20261011','port'=>18721],'C'=>['pid'=>2070149,'root'=>'/tmp/cdx-nutrition-ts8-C-20261011','port'=>18722]];if(!isset($targets[$lane]))exit(78);$target=$targets[$lane];if(!is_dir($target['root'])||is_link($target['root'])||realpath($target['root'])!==$target['root'])throw new RuntimeException('Exact owned root');$cmd=(string)file_get_contents('/proc/'.$target['pid'].'/cmdline');if(strpos($cmd,$target['root'].'/index.php')===false)throw new RuntimeException('Exact owned PID');if(!posix_kill($target['pid'],SIGTERM))throw new RuntimeException('Own worker stop');usleep(300000);if($socket=@fsockopen('127.0.0.1',$target['port'],$n,$e,1)){fclose($socket);throw new RuntimeException('Own port remains');}
$remove=static function($path)use(&$remove):void {if(is_link($path)||is_file($path)){if(!unlink($path))throw new RuntimeException('Own file cleanup');return;}foreach(scandir($path) as $item)if($item!=='.'&&$item!=='..')$remove($path.'/'.$item);if(!rmdir($path))throw new RuntimeException('Own directory cleanup');};$remove($target['root']);clearstatcache();if(file_exists($target['root']))throw new RuntimeException('Own root remains');echo json_encode(['lane'=>$lane,'pid'=>$target['pid'],'port'=>$target['port'],'port_closed'=>true,'auth_cache_config_source_runtime_removed'=>true,'retained_own_fixture_rows'=>$lane==='B'?2:4,'original_service_alive'=>is_dir('/proc/'.($lane==='B'?10001:112175))]),"\n";
