1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Refactor container.Start()

This commit is contained in:
Guillaume J. Charmes 2013-10-16 13:12:56 -07:00
parent 664acd2971
commit ed6ca109bf
No known key found for this signature in database
GPG key ID: B33E4642CB6E3FF3

View file

@ -563,11 +563,14 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
}) })
} }
func (container *Container) Start(hostConfig *HostConfig) error { func (container *Container) Start(hostConfig *HostConfig) (err error) {
container.State.Lock() container.State.Lock()
defer container.State.Unlock() defer container.State.Unlock()
defer func() {
startFct := func(hostConfig *HostConfig) error { if err != nil {
container.cleanup()
}
}()
if hostConfig == nil { // in docker start of docker restart we want to reuse previous HostConfigFile if hostConfig == nil { // in docker start of docker restart we want to reuse previous HostConfigFile
hostConfig, _ = container.ReadHostConfig() hostConfig, _ = container.ReadHostConfig()
@ -805,7 +808,6 @@ func (container *Container) Start(hostConfig *HostConfig) error {
container.cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} container.cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
var err error
if container.Config.Tty { if container.Config.Tty {
err = container.startPty() err = container.startPty()
} else { } else {
@ -826,12 +828,6 @@ func (container *Container) Start(hostConfig *HostConfig) error {
go container.monitor(hostConfig) go container.monitor(hostConfig)
return nil return nil
} }
err := startFct(hostConfig)
if err != nil {
container.cleanup()
}
return err
}
func (container *Container) Run() error { func (container *Container) Run() error {
hostConfig := &HostConfig{} hostConfig := &HostConfig{}