Check error return from json.Unmarshal
Signed-off-by: Ted Yu <yuzhihong@gmail.com> Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -521,13 +521,8 @@ func (s *Service) checkProcesses(e runc.Exit) {
|
||||
}
|
||||
|
||||
if ip, ok := p.(*process.Init); ok {
|
||||
shouldKillAll, err := shouldKillAllOnExit(s.bundle)
|
||||
if err != nil {
|
||||
log.G(s.context).WithError(err).Error("failed to check shouldKillAll")
|
||||
}
|
||||
|
||||
// Ensure all children are killed
|
||||
if shouldKillAll {
|
||||
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")
|
||||
@@ -547,23 +542,25 @@ func (s *Service) checkProcesses(e runc.Exit) {
|
||||
}
|
||||
}
|
||||
|
||||
func shouldKillAllOnExit(bundlePath string) (bool, error) {
|
||||
func shouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
|
||||
var bundleSpec specs.Spec
|
||||
bundleConfigContents, err := ioutil.ReadFile(filepath.Join(bundlePath, "config.json"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json")
|
||||
return true
|
||||
}
|
||||
if err := json.Unmarshal(bundleConfigContents, &bundleSpec); err != nil {
|
||||
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to unmarshal bundle json")
|
||||
return true
|
||||
}
|
||||
json.Unmarshal(bundleConfigContents, &bundleSpec)
|
||||
|
||||
if bundleSpec.Linux != nil {
|
||||
for _, ns := range bundleSpec.Linux.Namespaces {
|
||||
if ns.Type == specs.PIDNamespace && ns.Path == "" {
|
||||
return false, nil
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Service) getContainerPids(ctx context.Context, id string) ([]uint32, error) {
|
||||
|
||||
Reference in New Issue
Block a user