From eb9a561b18279931c320e2bb330779c38591c59c Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 26 Jun 2014 11:38:53 -0700 Subject: [PATCH] Address review comments Ensure that the command is killed if we receive an error from the child Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- namespaces/exec.go | 4 +++- namespaces/init.go | 2 +- namespaces/sync_pipe.go | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/namespaces/exec.go b/namespaces/exec.go index e32da4b86..0aa2bb9c7 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -94,7 +94,9 @@ func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string defer libcontainer.DeleteState(dataPath) // Sync with child - if err := syncPipe.BlockOnChild(); err != nil { + if err := syncPipe.ReadFromChild(); err != nil { + command.Process.Kill() + command.Wait() return -1, err } diff --git a/namespaces/init.go b/namespaces/init.go index 4a6ce6e3a..53d2611b8 100644 --- a/namespaces/init.go +++ b/namespaces/init.go @@ -30,7 +30,7 @@ import ( func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) (err error) { defer func() { if err != nil { - syncPipe.ReportError(err) + syncPipe.ReportChildError(err) } }() diff --git a/namespaces/sync_pipe.go b/namespaces/sync_pipe.go index ae6fefc30..2160243e4 100644 --- a/namespaces/sync_pipe.go +++ b/namespaces/sync_pipe.go @@ -60,10 +60,10 @@ func (s *SyncPipe) SendToChild(networkState *network.NetworkState) error { return nil } -func (s *SyncPipe) BlockOnChild() error { +func (s *SyncPipe) ReadFromChild() error { data, err := ioutil.ReadAll(s.parent) if err != nil { - return nil + return err } if len(data) > 0 { return fmt.Errorf("Child error: %s", string(data)) @@ -86,7 +86,7 @@ func (s *SyncPipe) ReadFromParent() (*network.NetworkState, error) { } -func (s *SyncPipe) ReportError(err error) { +func (s *SyncPipe) ReportChildError(err error) { s.child.Write([]byte(err.Error())) s.CloseChild() }