@@ -87,7 +87,8 @@ pub(super) fn launch_child(
8787 options : & Launch < ' _ > ,
8888 check : impl FnOnce ( ) -> Result < ( ) , CandidateError > ,
8989) -> Result < std:: process:: Child , CandidateError > {
90- let mut command = Command :: new ( std:: env:: current_exe ( ) . map_err ( state:: io) ?) ;
90+ let executable = std:: env:: current_exe ( ) . map_err ( state:: io) ?;
91+ let mut command = super :: process:: publisher_command ( & executable) ;
9192 command. arg ( "--internal-publication-child" ) ;
9293 launch_child_with ( candidate, options, check, command)
9394}
@@ -108,9 +109,13 @@ fn launch_child_with(
108109 let mut committed = false ;
109110 let result = ( || {
110111 let mut gate = child. stdin . take ( ) . ok_or_else ( error) ?;
112+ #[ cfg( debug_assertions) ]
113+ super :: graph:: publisher_recovery_fault ( candidate, options. run , "publisher-gated" ) ?;
111114 let process = identity:: observe ( child. id ( ) as i32 ) ?;
112115 let entry = stage_launch ( candidate, options, process) ?;
113116 committed = true ;
117+ #[ cfg( debug_assertions) ]
118+ super :: graph:: publisher_recovery_fault ( candidate, options. run , "publisher-committed" ) ?;
114119 let request = ChildLaunch {
115120 entry,
116121 upstream : options. upstream . into ( ) ,
@@ -122,7 +127,11 @@ fn launch_child_with(
122127 check ( ) ?;
123128 // Encode authorization after the complete payload. EOF alone is a refusal.
124129 gate. write_all ( & bytes) . map_err ( state:: io) ?;
125- gate. write_all ( b"\n " ) . map_err ( state:: io)
130+ gate. write_all ( b"\n " ) . map_err ( state:: io) ?;
131+ #[ cfg( debug_assertions) ]
132+ let _ =
133+ super :: graph:: publisher_recovery_fault ( candidate, options. run , "publisher-authorized" ) ;
134+ Ok ( ( ) )
126135 } ) ( ) ;
127136 if let Err ( error) = result {
128137 child. wait ( ) . map_err ( state:: io) ?;
@@ -700,10 +709,13 @@ fn check_socket(
700709 . map_err ( state:: io)
701710}
702711fn cleanup ( e : & Entry ) -> Result < ( ) , CandidateError > {
712+ let control = directory ( e) . join ( "control" ) ;
713+ #[ cfg( target_os = "macos" ) ]
714+ wait_for_authorized_child ( e, & control) ?;
703715 let options = publisher:: StopOptions {
704716 process : & e. process ,
705717 binary : & e. process . executable ,
706- control : & directory ( e ) . join ( " control" ) ,
718+ control : & control,
707719 token : & e. token ,
708720 } ;
709721 #[ cfg( target_os = "macos" ) ]
@@ -793,6 +805,28 @@ fn cleanup(e: &Entry) -> Result<(), CandidateError> {
793805 . map_err ( state:: io)
794806}
795807
808+ /// A committed child may still be between authorization and the control bind.
809+ /// Wait only for that exact incarnation to exit or reach the normal stop path.
810+ #[ cfg( target_os = "macos" ) ]
811+ fn wait_for_authorized_child ( e : & Entry , control : & Path ) -> Result < ( ) , CandidateError > {
812+ use std:: time:: { Duration , Instant } ;
813+ if !e. binary . as_ref ( ) . is_some_and ( |binary| binary. ready ) {
814+ return Ok ( ( ) ) ;
815+ }
816+ let deadline = Instant :: now ( ) + Duration :: from_secs ( 2 ) ;
817+ loop {
818+ match fs:: symlink_metadata ( control) {
819+ Ok ( _) => return Ok ( ( ) ) ,
820+ Err ( error) if error. kind ( ) == std:: io:: ErrorKind :: NotFound => { }
821+ Err ( error) => return Err ( state:: io ( error) ) ,
822+ }
823+ if entry_gone ( e) ? || Instant :: now ( ) >= deadline {
824+ return Ok ( ( ) ) ;
825+ }
826+ std:: thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
827+ }
828+ }
829+
796830/// The caller holds the provider lease; require every selected recorded process to be absent before
797831/// any guest cleanup. A reused, live or inaccessible PID conservatively refuses.
798832#[ cfg( target_os = "macos" ) ]
@@ -1055,6 +1089,30 @@ fn verify_claim_snapshot(
10551089 }
10561090 Ok ( ( ) )
10571091}
1092+
1093+ /// Lease-free presentation of the verified TCP listeners of one receipt.
1094+ #[ cfg( target_os = "macos" ) ]
1095+ pub ( super ) fn observed_run_ports (
1096+ candidate : & Candidate ,
1097+ owner : & str ,
1098+ run : & str ,
1099+ ) -> Result < Vec < u16 > , CandidateError > {
1100+ let entries = load ( candidate, owner) ?;
1101+ let observed = entries
1102+ . values ( )
1103+ . filter ( |entry| entry. run == run && !entry. unix )
1104+ . filter ( |entry| observe_publication ( entry) . is_ok ( ) )
1105+ . collect :: < Vec < _ > > ( ) ;
1106+ let after_owner = state:: Owner :: load ( candidate) ?;
1107+ let after = load ( candidate, & after_owner. token ) ?;
1108+ observed
1109+ . into_iter ( )
1110+ . map ( |entry| {
1111+ verify_claim_snapshot ( entry, & after, & after_owner. token ) ?;
1112+ Ok ( entry. port )
1113+ } )
1114+ . collect ( )
1115+ }
10581116/// A point-in-time observation, not a persistent capability or guest health claim.
10591117pub fn lookup_hostname ( c : & Candidate , value : & str ) -> Result < serde_json:: Value , CandidateError > {
10601118 let name = normalize_hostname ( value) ?;
0 commit comments