@@ -169,6 +169,8 @@ pub(crate) fn open_tree_from_pidns(
169
169
// We're in the child. At this point we know we don't have multiple threads, so we
170
170
// can safely `setns`.
171
171
172
+ drop ( sock_parent) ;
173
+
172
174
// Open up the namespace of the target process as a file descriptor, and enter it.
173
175
let pidlink = fs:: File :: open ( format ! ( "/proc/{}/ns/mnt" , pid. as_raw_nonzero( ) ) ) ?;
174
176
rustix:: thread:: move_into_link_name_space (
@@ -210,6 +212,7 @@ pub(crate) fn open_tree_from_pidns(
210
212
n => {
211
213
// We're in the parent; create a pid (checking that n > 0).
212
214
let pid = rustix:: process:: Pid :: from_raw ( n) . unwrap ( ) ;
215
+ drop ( sock_child) ;
213
216
// Receive the mount file descriptor from the child
214
217
let mut cmsg_space = vec ! [ 0 ; rustix:: cmsg_space!( ScmRights ( 1 ) ) ] ;
215
218
let mut cmsg_buffer = rustix:: net:: RecvAncillaryBuffer :: new ( & mut cmsg_space) ;
@@ -224,7 +227,7 @@ pub(crate) fn open_tree_from_pidns(
224
227
)
225
228
. context ( "recvmsg" ) ?
226
229
. bytes ;
227
- assert_eq ! ( nread, DUMMY_DATA . len( ) ) ;
230
+ anyhow :: ensure !( nread == DUMMY_DATA . len( ) ) ;
228
231
assert_eq ! ( buf, DUMMY_DATA ) ;
229
232
// And extract the file descriptor
230
233
let r = cmsg_buffer
@@ -236,8 +239,14 @@ pub(crate) fn open_tree_from_pidns(
236
239
. flatten ( )
237
240
. next ( )
238
241
. ok_or_else ( || anyhow:: anyhow!( "Did not receive a file descriptor" ) ) ?;
239
- rustix:: process:: waitpid ( Some ( pid) , WaitOptions :: empty ( ) ) ?;
240
- Ok ( r)
242
+ // SAFETY: Since we're not setting WNOHANG, this will always return Some().
243
+ let st =
244
+ rustix:: process:: waitpid ( Some ( pid) , WaitOptions :: empty ( ) ) ?. expect ( "Wait status" ) ;
245
+ if let Some ( 0 ) = st. exit_status ( ) {
246
+ Ok ( r)
247
+ } else {
248
+ anyhow:: bail!( "forked helper failed: {st:?}" ) ;
249
+ }
241
250
}
242
251
}
243
252
}
0 commit comments