@@ -29,7 +29,7 @@ static NEXT_GENERATION: AtomicU64 = AtomicU64::new(1);
2929/// removing a newer child that reused the same numeric PID after reap.
3030#[ cfg( target_os = "linux" ) ]
3131#[ derive( Clone , Copy ) ]
32- pub struct ManagedChildRegistration {
32+ struct ManagedChildRegistration {
3333 pid : i32 ,
3434 generation : u64 ,
3535}
@@ -42,12 +42,12 @@ pub struct ManagedChildRegistration {
4242/// otherwise unavoidable window in which a fast-exiting managed child exists
4343/// but its PID has not yet been published.
4444#[ cfg( target_os = "linux" ) ]
45- pub struct RegistryGuard ( MutexGuard < ' static , HashMap < i32 , u64 > > ) ;
45+ struct RegistryGuard ( MutexGuard < ' static , HashMap < i32 , u64 > > ) ;
4646
4747#[ cfg( target_os = "linux" ) ]
4848impl RegistryGuard {
4949 /// Add a newly spawned managed child.
50- pub fn register ( & mut self , pid : u32 ) -> Option < ManagedChildRegistration > {
50+ fn register ( & mut self , pid : u32 ) -> Option < ManagedChildRegistration > {
5151 let Ok ( pid) = i32:: try_from ( pid) else {
5252 return None ;
5353 } ;
@@ -61,32 +61,26 @@ impl RegistryGuard {
6161
6262 /// Return whether the PID belongs to an explicit waiter.
6363 #[ must_use]
64- pub fn contains ( & self , pid : i32 ) -> bool {
64+ fn contains ( & self , pid : i32 ) -> bool {
6565 self . 0 . contains_key ( & pid)
6666 }
6767}
6868
6969/// Lock the registry for an atomic spawn-and-register or inspect-and-reap
7070/// operation.
7171#[ cfg( target_os = "linux" ) ]
72- pub fn lock ( ) -> RegistryGuard {
72+ fn lock ( ) -> RegistryGuard {
7373 RegistryGuard (
7474 MANAGED_CHILDREN
7575 . lock ( )
7676 . unwrap_or_else ( std:: sync:: PoisonError :: into_inner) ,
7777 )
7878}
7979
80- /// Register a child and return the generation-bearing removal token.
81- #[ cfg( target_os = "linux" ) ]
82- pub fn register ( pid : u32 ) -> Option < ManagedChildRegistration > {
83- lock ( ) . register ( pid)
84- }
85-
8680/// Remove exactly this supervised-child registration. A newer registration
8781/// for a reused PID is preserved.
8882#[ cfg( target_os = "linux" ) ]
89- pub fn unregister ( child : ManagedChildRegistration ) {
83+ fn unregister ( child : ManagedChildRegistration ) {
9084 if let Ok ( mut children) = MANAGED_CHILDREN . lock ( )
9185 && children. get ( & child. pid ) == Some ( & child. generation )
9286 {
@@ -95,9 +89,9 @@ pub fn unregister(child: ManagedChildRegistration) {
9589}
9690
9791/// Return `true` if `pid` is currently in the supervised-child set.
98- #[ cfg( target_os = "linux" ) ]
92+ #[ cfg( all ( test , target_os = "linux" ) ) ]
9993#[ must_use]
100- pub fn is_managed ( pid : i32 ) -> bool {
94+ fn is_managed ( pid : i32 ) -> bool {
10195 lock ( ) . contains ( pid)
10296}
10397
@@ -112,7 +106,7 @@ fn valid_pid(pid: Option<u32>) -> Option<u32> {
112106/// insertion, so the orphan reaper cannot consume a fast child's status
113107/// between those operations. Other platforms retain the same ownership API
114108/// without enabling Linux-only reaper bookkeeping.
115- pub struct ManagedChild < C > {
109+ pub ( crate ) struct ManagedChild < C > {
116110 child : C ,
117111 pid : Option < u32 > ,
118112 #[ cfg( target_os = "linux" ) ]
@@ -121,7 +115,7 @@ pub struct ManagedChild<C> {
121115
122116impl < C > ManagedChild < C > {
123117 /// Spawn a child and register its PID before returning it.
124- pub fn spawn < E > (
118+ pub ( crate ) fn spawn < E > (
125119 spawn : impl FnOnce ( ) -> Result < C , E > ,
126120 pid : impl FnOnce ( & C ) -> Option < u32 > ,
127121 ) -> Result < Self , E > {
@@ -148,7 +142,7 @@ impl<C> ManagedChild<C> {
148142
149143 /// Return the child's PID when it was available at spawn time.
150144 #[ must_use]
151- pub const fn id ( & self ) -> Option < u32 > {
145+ pub ( crate ) const fn id ( & self ) -> Option < u32 > {
152146 self . pid
153147 }
154148
@@ -179,7 +173,7 @@ fn log_wait_error(pid: Option<u32>, error: &std::io::Error) {
179173
180174impl ManagedChild < tokio:: process:: Child > {
181175 /// Wait for a Tokio child and release its managed PID.
182- pub async fn wait ( & mut self ) -> std:: io:: Result < std:: process:: ExitStatus > {
176+ pub ( crate ) async fn wait ( & mut self ) -> std:: io:: Result < std:: process:: ExitStatus > {
183177 let status = self . child . wait ( ) . await ;
184178 if let Err ( error) = & status {
185179 log_wait_error ( self . pid , error) ;
@@ -189,7 +183,7 @@ impl ManagedChild<tokio::process::Child> {
189183 }
190184
191185 /// Observe a Tokio child without blocking.
192- pub fn try_wait ( & mut self ) -> std:: io:: Result < Option < std:: process:: ExitStatus > > {
186+ pub ( crate ) fn try_wait ( & mut self ) -> std:: io:: Result < Option < std:: process:: ExitStatus > > {
193187 match self . child . try_wait ( ) {
194188 Ok ( status) => {
195189 if status. is_some ( ) {
@@ -206,24 +200,24 @@ impl ManagedChild<tokio::process::Child> {
206200 }
207201
208202 /// Take the child's stdin handle without exposing the child itself.
209- pub fn take_stdin ( & mut self ) -> Option < tokio:: process:: ChildStdin > {
203+ pub ( crate ) fn take_stdin ( & mut self ) -> Option < tokio:: process:: ChildStdin > {
210204 self . child . stdin . take ( )
211205 }
212206
213207 /// Take the child's stdout handle without exposing the child itself.
214- pub fn take_stdout ( & mut self ) -> Option < tokio:: process:: ChildStdout > {
208+ pub ( crate ) fn take_stdout ( & mut self ) -> Option < tokio:: process:: ChildStdout > {
215209 self . child . stdout . take ( )
216210 }
217211
218212 /// Take the child's stderr handle without exposing the child itself.
219- pub fn take_stderr ( & mut self ) -> Option < tokio:: process:: ChildStderr > {
213+ pub ( crate ) fn take_stderr ( & mut self ) -> Option < tokio:: process:: ChildStderr > {
220214 self . child . stderr . take ( )
221215 }
222216}
223217
224218impl ManagedChild < std:: process:: Child > {
225219 /// Wait for a standard-library child and release its managed PID.
226- pub fn wait ( & mut self ) -> std:: io:: Result < std:: process:: ExitStatus > {
220+ pub ( crate ) fn wait ( & mut self ) -> std:: io:: Result < std:: process:: ExitStatus > {
227221 let status = self . child . wait ( ) ;
228222 if let Err ( error) = & status {
229223 log_wait_error ( self . pid , error) ;
@@ -233,17 +227,17 @@ impl ManagedChild<std::process::Child> {
233227 }
234228
235229 /// Take the child's stdin handle without exposing the child itself.
236- pub fn take_stdin ( & mut self ) -> Option < std:: process:: ChildStdin > {
230+ pub ( crate ) fn take_stdin ( & mut self ) -> Option < std:: process:: ChildStdin > {
237231 self . child . stdin . take ( )
238232 }
239233
240234 /// Take the child's stdout handle without exposing the child itself.
241- pub fn take_stdout ( & mut self ) -> Option < std:: process:: ChildStdout > {
235+ pub ( crate ) fn take_stdout ( & mut self ) -> Option < std:: process:: ChildStdout > {
242236 self . child . stdout . take ( )
243237 }
244238
245239 /// Take the child's stderr handle without exposing the child itself.
246- pub fn take_stderr ( & mut self ) -> Option < std:: process:: ChildStderr > {
240+ pub ( crate ) fn take_stderr ( & mut self ) -> Option < std:: process:: ChildStderr > {
247241 self . child . stderr . take ( )
248242 }
249243}
@@ -253,7 +247,7 @@ impl ManagedChild<std::process::Child> {
253247/// Keeping the child as a zombie prevents PID/process-group reuse until the
254248/// owner publishes terminal state and performs the final wait.
255249#[ cfg( target_os = "linux" ) ]
256- pub fn wait_until_terminal ( pid : u32 ) -> io:: Result < ( ) > {
250+ pub ( crate ) fn wait_until_terminal ( pid : u32 ) -> io:: Result < ( ) > {
257251 use nix:: sys:: wait:: { Id , WaitPidFlag , waitid} ;
258252 let pid = i32:: try_from ( pid)
259253 . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "PID out of range" ) ) ?;
@@ -270,7 +264,7 @@ pub fn wait_until_terminal(pid: u32) -> io::Result<()> {
270264/// Explicitly managed children remain owned by their normal waiters. Only
271265/// unregistered children adopted from the workload process tree are reaped.
272266#[ cfg( target_os = "linux" ) ]
273- pub fn start_orphan_reaper ( ) -> io:: Result < ( ) > {
267+ pub ( crate ) fn start_orphan_reaper ( ) -> io:: Result < ( ) > {
274268 std:: thread:: Builder :: new ( )
275269 . name ( "openshell-orphan-reaper" . to_string ( ) )
276270 . spawn ( || {
0 commit comments