From 13e8f6e58991e9d5cb69504e0ba7dcf49dc5b51b Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Sat, 30 Jan 2016 13:41:21 +0800 Subject: [PATCH] Remove procStart It's never used and not needed. Our pipe is created with syscall.SOCK_CLOEXEC, so pipe will be closed once container process executed successfully, parent process will read EOF and continue. If container process got error before executed, we'll write procError to sync with parent. Signed-off-by: Qiang Huang --- libcontainer/factory_linux.go | 24 ++++++++++-------------- libcontainer/generic_error.go | 1 - libcontainer/process_linux.go | 2 -- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index f5973836c..e45c5ca6f 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -232,23 +232,19 @@ func (l *LinuxFactory) StartInitialization() (err error) { os.Clearenv() var i initer defer func() { - // if we have an error during the initialization of the container's init then send it back to the - // parent process in the form of an initError. - if err != nil { - if _, ok := i.(*linuxStandardInit); ok { - // Synchronisation only necessary for standard init. - if err := utils.WriteJSON(pipe, syncT{procError}); err != nil { - panic(err) - } - } - if err := utils.WriteJSON(pipe, newSystemError(err)); err != nil { - panic(err) - } - } else { - if err := utils.WriteJSON(pipe, syncT{procStart}); err != nil { + // We have an error during the initialization of the container's init, + // send it back to the parent process in the form of an initError. + // If container's init successed, syscall.Exec will not return, hence + // this defer function will never be called. + if _, ok := i.(*linuxStandardInit); ok { + // Synchronisation only necessary for standard init. + if err := utils.WriteJSON(pipe, syncT{procError}); err != nil { panic(err) } } + if err := utils.WriteJSON(pipe, newSystemError(err)); err != nil { + panic(err) + } // ensure that this pipe is always closed pipe.Close() }() diff --git a/libcontainer/generic_error.go b/libcontainer/generic_error.go index 924d637b2..75e980b1d 100644 --- a/libcontainer/generic_error.go +++ b/libcontainer/generic_error.go @@ -14,7 +14,6 @@ type syncType uint8 const ( procReady syncType = iota procError - procStart procRun ) diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go index 353c87e92..aa9b9d098 100644 --- a/libcontainer/process_linux.go +++ b/libcontainer/process_linux.go @@ -247,8 +247,6 @@ loop: return newSystemError(err) } switch procSync.Type { - case procStart: - break loop case procReady: if err := p.manager.Set(p.config.Config); err != nil { return newSystemError(err)