<?php
$lane=$argv[1]??'';$roots=['B'=>'/tmp/cdx-weight-B.OCutZD','C'=>'/tmp/cdx-weight-C.2dCrh9'];$pids=['B'=>97815,'C'=>1835249];$parents=['B'=>10001,'C'=>112175];$ports=['B'=>18321,'C'=>18322];if(!isset($roots[$lane])||__DIR__!==$roots[$lane]||is_link(__DIR__))throw new RuntimeException('Exact owned root');$pid=$pids[$lane];$cmd=(string)file_get_contents('/proc/'.$pid.'/cmdline');if(strpos($cmd,__DIR__.'/index.php')===false||strpos($cmd,'127.0.0.1:'.$ports[$lane])===false)throw new RuntimeException('Exact owned command');if(!is_file('/proc/'.$parents[$lane].'/cmdline'))throw new RuntimeException('Parent must stay');if(!posix_kill($pid,15))throw new RuntimeException('Stop failed');for($i=0;$i<30;$i++){if(!$s=@fsockopen('127.0.0.1',$ports[$lane],$n,$e,0.1))break;fclose($s);usleep(100000);}if($s=@fsockopen('127.0.0.1',$ports[$lane],$n,$e,0.1)){fclose($s);throw new RuntimeException('Port not closed');}$count=0;$remove=static function($path)use(&$remove,&$count):void{if(is_link($path))throw new RuntimeException('Unexpected symlink');if(is_dir($path)){foreach(scandir($path)as $name)if($name!=='.'&&$name!=='..')$remove($path.'/'.$name);rmdir($path);}else{unlink($path);$count++;}};$remove(__DIR__);echo json_encode(['lane'=>$lane,'owned_pid'=>$pid,'exact_cmdline_verified'=>true,'stopped'=>true,'port_closed'=>true,'runtime_removed'=>!file_exists(__DIR__),'files_removed'=>$count,'original_parent_alive'=>is_file('/proc/'.$parents[$lane].'/cmdline'),'CLI_cache_preserved'=>is_file('/tmp/cdx-apifox-cli-2.2.8-cache/package/bin/cli.js')]),"\n";
