<?php
$lane=$argv[1]??'';$targets=['B'=>['pid'=>1388,'root'=>'/tmp/cdx-nutrition-read5-B-20261011','port'=>18341],'C'=>['pid'=>2023798,'root'=>'/tmp/cdx-nutrition-read5-C-20261011','port'=>18342]];
if(!isset($targets[$lane]))exit(78);$t=$targets[$lane];
if(!is_dir($t['root'])||is_link($t['root'])||realpath($t['root'])!==$t['root'])throw new RuntimeException('Exact owned runtime root gate');
$cmd=(string)file_get_contents('/proc/'.$t['pid'].'/cmdline');if(strpos($cmd,$t['root'].'/index.php')===false)throw new RuntimeException('Exact owned PID gate');
if(!posix_kill($t['pid'],SIGTERM))throw new RuntimeException('Stop failed');usleep(300000);
if($socket=@fsockopen('127.0.0.1',$t['port'],$n,$e,1)){fclose($socket);throw new RuntimeException('Port still occupied');}
$delete=static function($path)use(&$delete):void {if(is_link($path)||is_file($path)){if(!unlink($path))throw new RuntimeException('Owned file cleanup');return;}foreach(scandir($path) as $item)if($item!=='.'&&$item!=='..')$delete($path.'/'.$item);if(!rmdir($path))throw new RuntimeException('Owned directory cleanup');};
$delete($t['root']);clearstatcache();if(file_exists($t['root']))throw new RuntimeException('Runtime still exists');
echo json_encode(['lane'=>$lane,'owned_pid'=>$t['pid'],'owned_port'=>$t['port'],'port_closed'=>true,'owned_runtime_removed'=>true,'auth_cache_config_source_removed'=>true,'retained_fixture_rows'=>$lane==='C'?2:0,'original_service_alive'=>is_dir('/proc/'.($lane==='B'?10001:112175))]),"\n";
