Merge pull request #4058 from tedyu/get-process

Avoid allocating slice for finding Process
This commit is contained in:
Michael Crosby 2020-03-06 13:16:18 -05:00 committed by GitHub
commit 97ca1be067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -503,23 +503,20 @@ func (s *Service) processExits() {
} }
} }
func (s *Service) allProcesses() []process.Process {
s.mu.Lock()
defer s.mu.Unlock()
res := make([]process.Process, 0, len(s.processes))
for _, p := range s.processes {
res = append(res, p)
}
return res
}
func (s *Service) checkProcesses(e runc.Exit) { func (s *Service) checkProcesses(e runc.Exit) {
for _, p := range s.allProcesses() { var p process.Process
if p.Pid() != e.Pid { s.mu.Lock()
continue for _, proc := range s.processes {
if proc.Pid() == e.Pid {
p = proc
break
}
}
s.mu.Unlock()
if p == nil {
log.G(s.context).Infof("process with id:%d wasn't found", e.Pid)
return
} }
if ip, ok := p.(*process.Init); ok { if ip, ok := p.(*process.Init); ok {
// Ensure all children are killed // Ensure all children are killed
if shouldKillAllOnExit(s.context, s.bundle) { if shouldKillAllOnExit(s.context, s.bundle) {
@ -538,8 +535,6 @@ func (s *Service) checkProcesses(e runc.Exit) {
ExitStatus: uint32(e.Status), ExitStatus: uint32(e.Status),
ExitedAt: p.ExitedAt(), ExitedAt: p.ExitedAt(),
} }
return
}
} }
func shouldKillAllOnExit(ctx context.Context, bundlePath string) bool { func shouldKillAllOnExit(ctx context.Context, bundlePath string) bool {