mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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:
+3
-1
@@ -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
@@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user