<?php
$lane=$argv[1]??'';$targets=['B'=>['pid'=>1858,'root'=>'/tmp/cdx-nutrition-product10-B-20261011','port'=>18361],'C'=>['pid'=>2046255,'root'=>'/tmp/cdx-nutrition-product10-C-20261011','port'=>18362]];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 gate');$cmd=(string)file_get_contents('/proc/'.$target['pid'].'/cmdline');if(strpos($cmd,$target['root'].'/index.php')===false)throw new RuntimeException('Exact owned PID gate');
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 still listening');}
$delete=static function($path)use(&$delete):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!=='..')$delete($path.'/'.$item);if(!rmdir($path))throw new RuntimeException('Own directory cleanup');};$delete($target['root']);clearstatcache();if(file_exists($target['root']))throw new RuntimeException('Root remains');
echo json_encode(['lane'=>$lane,'pid'=>$target['pid'],'port'=>$target['port'],'port_closed'=>true,'runtime_auth_cache_config_source_removed'=>true,'retained_own_fixture_rows'=>$lane==='C'?1:0,'original_service_alive'=>is_dir('/proc/'.($lane==='B'?10001:112175))]),"\n";
