Revert "exec: get the exit code from sync pipe instead of file"

This reverts commit 4b72f9e4013411208751df2a92ab9f322d4da5b2.

Continues what began with revert of
d3d97a25e8c87cf741b2e24ac01ef84962137106 in previous commit.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
Matthew Heon
2020-03-09 09:49:27 -04:00
parent ffce869daa
commit 521ff14d83
6 changed files with 63 additions and 83 deletions

View File

@ -282,16 +282,7 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
opts.Resize = resize
opts.DetachKeys = detachKeys
pid := 0
pipeDataChan, attachChan, err := c.ociRuntime.ExecContainer(c, sessionID, opts)
// if pipeDataChan isn't nil, we should set the err
if pipeDataChan != nil {
pidData := <-pipeDataChan
if pidData.err != nil {
err = pidData.err
}
pid = pidData.data
}
pid, attachChan, err := c.ociRuntime.ExecContainer(c, sessionID, opts)
if err != nil {
ec := define.ExecErrorCodeGeneric
// Conmon will pass a non-zero exit code from the runtime as a pid here.
@ -327,18 +318,18 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
lastErr := <-attachChan
exitCodeData := <-pipeDataChan
if exitCodeData.err != nil {
exitCode, err := c.readExecExitCode(sessionID)
if err != nil {
if lastErr != nil {
logrus.Errorf(lastErr.Error())
}
lastErr = exitCodeData.err
lastErr = err
}
if exitCodeData.data != 0 {
if exitCode != 0 {
if lastErr != nil {
logrus.Errorf(lastErr.Error())
}
lastErr = errors.Wrapf(define.ErrOCIRuntime, "non zero exit code: %d", exitCodeData.data)
lastErr = errors.Wrapf(define.ErrOCIRuntime, "non zero exit code: %d", exitCode)
}
// Lock again
@ -349,7 +340,7 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
// Sync the container again to pick up changes in state
if err := c.syncContainer(); err != nil {
logrus.Errorf("error syncing container %s state to remove exec session %s", c.ID(), sessionID)
return exitCodeData.data, lastErr
return exitCode, lastErr
}
// Remove the exec session from state
@ -357,7 +348,7 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
if err := c.save(); err != nil {
logrus.Errorf("Error removing exec session %s from container %s state: %v", sessionID, c.ID(), err)
}
return exitCodeData.data, lastErr
return exitCode, lastErr
}
// AttachStreams contains streams that will be attached to the container