Merge pull request #4062 from tedyu/start-shim-defer

Use named error return for service#StartShim
This commit is contained in:
Phil Estes
2020-02-27 13:23:31 -05:00
committed by GitHub

View File

@@ -159,7 +159,7 @@ func readSpec() (*spec, error) {
return &s, nil return &s, nil
} }
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) { func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) {
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress)
if err != nil { if err != nil {
return "", err return "", err
@@ -202,7 +202,7 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
return "", err return "", err
} }
defer func() { defer func() {
if err != nil { if retErr != nil {
cmd.Process.Kill() cmd.Process.Kill()
} }
}() }()