namespaces: destroy cgroups only on error paths

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-01-19 16:21:21 +03:00 committed by Andrew Vagin
parent 9c50d819ae
commit dcb3bca32c
1 changed files with 6 additions and 4 deletions

View File

@ -19,9 +19,7 @@ import (
// Move this to libcontainer package. // Move this to libcontainer package.
// Exec performs setup outside of a namespace so that a container can be // Exec performs setup outside of a namespace so that a container can be
// executed. Exec is a high level function for working with container namespaces. // executed. Exec is a high level function for working with container namespaces.
func Exec(args []string, env []string, console string, command *exec.Cmd, container *configs.Config, cgroupManager cgroups.Manager, state *configs.State) error { func Exec(args []string, env []string, console string, command *exec.Cmd, container *configs.Config, cgroupManager cgroups.Manager, state *configs.State) (err error) {
var err error
// create a pipe so that we can syncronize with the namespaced process and // create a pipe so that we can syncronize with the namespaced process and
// pass the state and configuration to the child process // pass the state and configuration to the child process
parent, child, err := newInitPipe() parent, child, err := newInitPipe()
@ -73,7 +71,11 @@ func Exec(args []string, env []string, console string, command *exec.Cmd, contai
if err != nil { if err != nil {
return terminate(err) return terminate(err)
} }
defer cgroupManager.Destroy() defer func() {
if err != nil {
cgroupManager.Destroy()
}
}()
var networkState network.NetworkState var networkState network.NetworkState
if err := InitializeNetworking(container, command.Process.Pid, &networkState); err != nil { if err := InitializeNetworking(container, command.Process.Pid, &networkState); err != nil {