Merge pull request #4058 from tedyu/get-process
Avoid allocating slice for finding Process
This commit is contained in:
commit
97ca1be067
@ -503,42 +503,37 @@ 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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ip, ok := p.(*process.Init); ok {
|
s.mu.Unlock()
|
||||||
// Ensure all children are killed
|
if p == nil {
|
||||||
if shouldKillAllOnExit(s.context, s.bundle) {
|
log.G(s.context).Infof("process with id:%d wasn't found", e.Pid)
|
||||||
if err := ip.KillAll(s.context); err != nil {
|
return
|
||||||
log.G(s.context).WithError(err).WithField("id", ip.ID()).
|
}
|
||||||
Error("failed to kill init's children")
|
if ip, ok := p.(*process.Init); ok {
|
||||||
}
|
// Ensure all children are killed
|
||||||
|
if shouldKillAllOnExit(s.context, s.bundle) {
|
||||||
|
if err := ip.KillAll(s.context); err != nil {
|
||||||
|
log.G(s.context).WithError(err).WithField("id", ip.ID()).
|
||||||
|
Error("failed to kill init's children")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.SetExited(e.Status)
|
p.SetExited(e.Status)
|
||||||
s.events <- &eventstypes.TaskExit{
|
s.events <- &eventstypes.TaskExit{
|
||||||
ContainerID: s.id,
|
ContainerID: s.id,
|
||||||
ID: p.ID(),
|
ID: p.ID(),
|
||||||
Pid: uint32(e.Pid),
|
Pid: uint32(e.Pid),
|
||||||
ExitStatus: uint32(e.Status),
|
ExitStatus: uint32(e.Status),
|
||||||
ExitedAt: p.ExitedAt(),
|
ExitedAt: p.ExitedAt(),
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user