Skip to content

Commit 640860a

Browse files
authored
Merge pull request #3559 from fuweid/avoid-read-config
runtime: only check killall for init process
2 parents cd76c41 + 1073868 commit 640860a

2 files changed

Lines changed: 51 additions & 44 deletions

File tree

runtime/v1/shim/service.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -515,33 +515,35 @@ func (s *Service) allProcesses() []process.Process {
515515
}
516516

517517
func (s *Service) checkProcesses(e runc.Exit) {
518-
shouldKillAll, err := shouldKillAllOnExit(s.bundle)
519-
if err != nil {
520-
log.G(s.context).WithError(err).Error("failed to check shouldKillAll")
521-
}
522-
523518
for _, p := range s.allProcesses() {
524-
if p.Pid() == e.Pid {
519+
if p.Pid() != e.Pid {
520+
continue
521+
}
525522

523+
if ip, ok := p.(*process.Init); ok {
524+
shouldKillAll, err := shouldKillAllOnExit(s.bundle)
525+
if err != nil {
526+
log.G(s.context).WithError(err).Error("failed to check shouldKillAll")
527+
}
528+
529+
// Ensure all children are killed
526530
if shouldKillAll {
527-
if ip, ok := p.(*process.Init); ok {
528-
// Ensure all children are killed
529-
if err := ip.KillAll(s.context); err != nil {
530-
log.G(s.context).WithError(err).WithField("id", ip.ID()).
531-
Error("failed to kill init's children")
532-
}
531+
if err := ip.KillAll(s.context); err != nil {
532+
log.G(s.context).WithError(err).WithField("id", ip.ID()).
533+
Error("failed to kill init's children")
533534
}
534535
}
535-
p.SetExited(e.Status)
536-
s.events <- &eventstypes.TaskExit{
537-
ContainerID: s.id,
538-
ID: p.ID(),
539-
Pid: uint32(e.Pid),
540-
ExitStatus: uint32(e.Status),
541-
ExitedAt: p.ExitedAt(),
542-
}
543-
return
544536
}
537+
538+
p.SetExited(e.Status)
539+
s.events <- &eventstypes.TaskExit{
540+
ContainerID: s.id,
541+
ID: p.ID(),
542+
Pid: uint32(e.Pid),
543+
ExitStatus: uint32(e.Status),
544+
ExitedAt: p.ExitedAt(),
545+
}
546+
return
545547
}
546548
}
547549

runtime/v2/runc/v2/service.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -646,36 +646,41 @@ func (s *service) checkProcesses(e runcC.Exit) {
646646
defer s.mu.Unlock()
647647

648648
for _, container := range s.containers {
649-
if container.HasPid(e.Pid) {
650-
shouldKillAll, err := shouldKillAllOnExit(container.Bundle)
651-
if err != nil {
652-
log.G(s.context).WithError(err).Error("failed to check shouldKillAll")
649+
if !container.HasPid(e.Pid) {
650+
continue
651+
}
652+
653+
for _, p := range container.All() {
654+
if p.Pid() != e.Pid {
655+
continue
653656
}
654657

655-
for _, p := range container.All() {
656-
if p.Pid() == e.Pid {
657-
if shouldKillAll {
658-
if ip, ok := p.(*process.Init); ok {
659-
// Ensure all children are killed
660-
if err := ip.KillAll(s.context); err != nil {
661-
logrus.WithError(err).WithField("id", ip.ID()).
662-
Error("failed to kill init's children")
663-
}
664-
}
658+
if ip, ok := p.(*process.Init); ok {
659+
shouldKillAll, err := shouldKillAllOnExit(container.Bundle)
660+
if err != nil {
661+
log.G(s.context).WithError(err).Error("failed to check shouldKillAll")
662+
}
663+
664+
// Ensure all children are killed
665+
if shouldKillAll {
666+
if err := ip.KillAll(s.context); err != nil {
667+
logrus.WithError(err).WithField("id", ip.ID()).
668+
Error("failed to kill init's children")
665669
}
666-
p.SetExited(e.Status)
667-
s.sendL(&eventstypes.TaskExit{
668-
ContainerID: container.ID,
669-
ID: p.ID(),
670-
Pid: uint32(e.Pid),
671-
ExitStatus: uint32(e.Status),
672-
ExitedAt: p.ExitedAt(),
673-
})
674-
return
675670
}
676671
}
672+
673+
p.SetExited(e.Status)
674+
s.sendL(&eventstypes.TaskExit{
675+
ContainerID: container.ID,
676+
ID: p.ID(),
677+
Pid: uint32(e.Pid),
678+
ExitStatus: uint32(e.Status),
679+
ExitedAt: p.ExitedAt(),
680+
})
677681
return
678682
}
683+
return
679684
}
680685
}
681686

0 commit comments

Comments
 (0)