From 957da1f9abdedbb1e998cd0eb854085e6373f8ac Mon Sep 17 00:00:00 2001 From: zyu Date: Mon, 9 Mar 2020 09:29:03 -0700 Subject: [PATCH] Use named error return for initProcess#start Signed-off-by: zyu --- libcontainer/process_linux.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go index de989b5bceb..51e54acae10 100644 --- a/libcontainer/process_linux.go +++ b/libcontainer/process_linux.go @@ -279,7 +279,7 @@ func (p *initProcess) waitForChildExit(childPid int) error { return nil } -func (p *initProcess) start() error { +func (p *initProcess) start() (retErr error) { defer p.messageSockPair.parent.Close() err := p.cmd.Start() p.process.ops = p @@ -290,6 +290,15 @@ func (p *initProcess) start() error { p.process.ops = nil 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 // 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. @@ -301,16 +310,6 @@ func (p *initProcess) start() error { 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 { 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") } - 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 { return newSystemErrorWithCause(err, "creating network interfaces") }