Merge pull request #2238 from tedyu/init-proc-err-ret

Use named error return for initProcess#start
This commit is contained in:
Akihiro Suda 2020-03-11 01:03:13 +09:00 committed by GitHub
commit 71dfb559d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 20 deletions

View File

@ -279,7 +279,7 @@ func (p *initProcess) waitForChildExit(childPid int) error {
return nil return nil
} }
func (p *initProcess) start() error { func (p *initProcess) start() (retErr error) {
defer p.messageSockPair.parent.Close() defer p.messageSockPair.parent.Close()
err := p.cmd.Start() err := p.cmd.Start()
p.process.ops = p p.process.ops = p
@ -290,6 +290,15 @@ func (p *initProcess) start() error {
p.process.ops = nil p.process.ops = nil
return newSystemErrorWithCause(err, "starting init process command") return newSystemErrorWithCause(err, "starting init process command")
} }
defer func() {
if retErr != nil {
p.manager.Destroy()
if p.intelRdtManager != nil {
p.intelRdtManager.Destroy()
}
}
}()
// Do this before syncing with child so that no children can escape the // Do this before syncing with child so that no children can escape the
// cgroup. We don't need to worry about not doing this and not being root // cgroup. We don't need to worry about not doing this and not being root
// because we'd be using the rootless cgroup manager in that case. // because we'd be using the rootless cgroup manager in that case.
@ -301,16 +310,6 @@ func (p *initProcess) start() error {
return newSystemErrorWithCause(err, "applying Intel RDT configuration for process") return newSystemErrorWithCause(err, "applying Intel RDT configuration for process")
} }
} }
defer func() {
if err != nil {
// TODO: should not be the responsibility to call here
p.manager.Destroy()
if p.intelRdtManager != nil {
p.intelRdtManager.Destroy()
}
}
}()
if _, err := io.Copy(p.messageSockPair.parent, p.bootstrapData); err != nil { if _, err := io.Copy(p.messageSockPair.parent, p.bootstrapData); err != nil {
return newSystemErrorWithCause(err, "copying bootstrap data to pipe") return newSystemErrorWithCause(err, "copying bootstrap data to pipe")
} }
@ -349,15 +348,6 @@ func (p *initProcess) start() error {
return newSystemErrorWithCause(err, "waiting for our first child to exit") return newSystemErrorWithCause(err, "waiting for our first child to exit")
} }
defer func() {
if err != nil {
// TODO: should not be the responsibility to call here
p.manager.Destroy()
if p.intelRdtManager != nil {
p.intelRdtManager.Destroy()
}
}
}()
if err := p.createNetworkInterfaces(); err != nil { if err := p.createNetworkInterfaces(); err != nil {
return newSystemErrorWithCause(err, "creating network interfaces") return newSystemErrorWithCause(err, "creating network interfaces")
} }