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 <michael@docker.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby
2014-06-26 11:38:53 -07:00
parent ca9544522e
commit eb9a561b18
3 changed files with 7 additions and 5 deletions
+3 -1
View File
@@ -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
}
+1 -1
View File
@@ -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)
}
}()
+3 -3
View File
@@ -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()
}