@@ -503,42 +503,37 @@ func (s *Service) processExits() {
503503 }
504504}
505505
506- func (s * Service ) allProcesses () []process.Process {
507- s .mu .Lock ()
508- defer s .mu .Unlock ()
509-
510- res := make ([]process.Process , 0 , len (s .processes ))
511- for _ , p := range s .processes {
512- res = append (res , p )
513- }
514- return res
515- }
516-
517506func (s * Service ) checkProcesses (e runc.Exit ) {
518- for _ , p := range s .allProcesses () {
519- if p .Pid () != e .Pid {
520- continue
507+ var p process.Process
508+ s .mu .Lock ()
509+ for _ , proc := range s .processes {
510+ if proc .Pid () == e .Pid {
511+ p = proc
512+ break
521513 }
522-
523- if ip , ok := p .(* process.Init ); ok {
524- // Ensure all children are killed
525- if shouldKillAllOnExit (s .context , s .bundle ) {
526- if err := ip .KillAll (s .context ); err != nil {
527- log .G (s .context ).WithError (err ).WithField ("id" , ip .ID ()).
528- Error ("failed to kill init's children" )
529- }
514+ }
515+ s .mu .Unlock ()
516+ if p == nil {
517+ log .G (s .context ).Infof ("process with id:%d wasn't found" , e .Pid )
518+ return
519+ }
520+ if ip , ok := p .(* process.Init ); ok {
521+ // Ensure all children are killed
522+ if shouldKillAllOnExit (s .context , s .bundle ) {
523+ if err := ip .KillAll (s .context ); err != nil {
524+ log .G (s .context ).WithError (err ).WithField ("id" , ip .ID ()).
525+ Error ("failed to kill init's children" )
530526 }
531527 }
528+ }
532529
533- p .SetExited (e .Status )
534- s .events <- & eventstypes.TaskExit {
535- ContainerID : s .id ,
536- ID : p .ID (),
537- Pid : uint32 (e .Pid ),
538- ExitStatus : uint32 (e .Status ),
539- ExitedAt : p .ExitedAt (),
540- }
541- return
530+ p .SetExited (e .Status )
531+ s .events <- & eventstypes.TaskExit {
532+ ContainerID : s .id ,
533+ ID : p .ID (),
534+ Pid : uint32 (e .Pid ),
535+ ExitStatus : uint32 (e .Status ),
536+ ExitedAt : p .ExitedAt (),
542537 }
543538}
544539
0 commit comments