@@ -272,8 +272,10 @@ impl Sandbox {
272
272
273
273
pub fn find_process ( & mut self , pid : pid_t ) -> Option < & mut Process > {
274
274
for ( _, c) in self . containers . iter_mut ( ) {
275
- if let Some ( p) = c. processes . get_mut ( & pid) {
276
- return Some ( p) ;
275
+ for p in c. processes . values_mut ( ) {
276
+ if p. pid == pid {
277
+ return Some ( p) ;
278
+ }
277
279
}
278
280
}
279
281
@@ -286,9 +288,11 @@ impl Sandbox {
286
288
. ok_or_else ( || anyhow ! ( ERR_INVALID_CONTAINER_ID ) ) ?;
287
289
288
290
if eid. is_empty ( ) {
291
+ let init_pid = ctr. init_process_pid ;
289
292
return ctr
290
293
. processes
291
- . get_mut ( & ctr. init_process_pid )
294
+ . values_mut ( )
295
+ . find ( |p| p. pid == init_pid)
292
296
. ok_or_else ( || anyhow ! ( "cannot find init process!" ) ) ;
293
297
}
294
298
@@ -1017,23 +1021,17 @@ mod tests {
1017
1021
linux_container. init_process_pid = 1 ;
1018
1022
linux_container. id = cid. to_string ( ) ;
1019
1023
// add init process
1024
+ let mut init_process = Process :: new ( & logger, & oci:: Process :: default ( ) , "1" , true , 1 , None ) . unwrap ( ) ;
1025
+ init_process. pid = 1 ;
1020
1026
linux_container. processes . insert (
1021
- 1 ,
1022
- Process :: new ( & logger, & oci:: Process :: default ( ) , "1" , true , 1 , None ) . unwrap ( ) ,
1023
- ) ;
1027
+ "1" . to_string ( ) ,
1028
+ init_process) ;
1024
1029
// add exec process
1030
+ let mut exec_process = Process :: new ( & logger, & oci:: Process :: default ( ) , "exec-123" , false , 1 , None ) . unwrap ( ) ;
1031
+ exec_process. pid = 123 ;
1025
1032
linux_container. processes . insert (
1026
- 123 ,
1027
- Process :: new (
1028
- & logger,
1029
- & oci:: Process :: default ( ) ,
1030
- "exec-123" ,
1031
- false ,
1032
- 1 ,
1033
- None ,
1034
- )
1035
- . unwrap ( ) ,
1036
- ) ;
1033
+ "exec-123" . to_string ( ) ,
1034
+ exec_process) ;
1037
1035
1038
1036
s. add_container ( linux_container) ;
1039
1037
@@ -1084,8 +1082,8 @@ mod tests {
1084
1082
. unwrap ( ) ;
1085
1083
// processes interally only have pids when manually set
1086
1084
test_process. pid = test_pid;
1087
-
1088
- linux_container. processes . insert ( test_pid , test_process) ;
1085
+ let test_exec_id = test_process . exec_id . clone ( ) ;
1086
+ linux_container. processes . insert ( test_exec_id , test_process) ;
1089
1087
1090
1088
s. add_container ( linux_container) ;
1091
1089
0 commit comments