summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2020-03-02 14:42:48 -0500
committerPeter Hunt <pehunt@redhat.com>2020-03-03 15:35:35 -0500
commit4b72f9e4013411208751df2a92ab9f322d4da5b2 (patch)
tree21abdfa291eaca2da67b0115fa4eed93eaa5aaa7 /libpod/container_api.go
parent3bc5f431d4df9724501a42a68e333f7e98a0b0cf (diff)
downloadpodman-4b72f9e4013411208751df2a92ab9f322d4da5b2.tar.gz
podman-4b72f9e4013411208751df2a92ab9f322d4da5b2.tar.bz2
podman-4b72f9e4013411208751df2a92ab9f322d4da5b2.zip
exec: get the exit code from sync pipe instead of file
Before, we were getting the exit code from the file, in which we waited an arbitrary amount of time (5 seconds) for the file, and segfaulted if we didn't find it. instead, we should be a bit more certain conmon has sent the exit code. Luckily, it sends the exit code along the sync pipe fd, so we can read it from there Adapt the ExecContainer interface to pass along a channel to get the pid and exit code from conmon, to be able to read both from the pipe Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index ee879b69d..37a05bb75 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -282,7 +282,16 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
opts.Resize = resize
opts.DetachKeys = detachKeys
- pid, attachChan, err := c.ociRuntime.ExecContainer(c, sessionID, opts)
+ 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
+ }
if err != nil {
ec := define.ExecErrorCodeGeneric
// Conmon will pass a non-zero exit code from the runtime as a pid here.
@@ -318,18 +327,18 @@ func (c *Container) Exec(tty, privileged bool, env map[string]string, cmd []stri
lastErr := <-attachChan
- exitCode, err := c.readExecExitCode(sessionID)
- if err != nil {
+ exitCodeData := <-pipeDataChan
+ if exitCodeData.err != nil {
if lastErr != nil {
logrus.Errorf(lastErr.Error())
}
- lastErr = err
+ lastErr = exitCodeData.err
}
- if exitCode != 0 {
+ if exitCodeData.data != 0 {
if lastErr != nil {
logrus.Errorf(lastErr.Error())
}
- lastErr = errors.Wrapf(define.ErrOCIRuntime, "non zero exit code: %d", exitCode)
+ lastErr = errors.Wrapf(define.ErrOCIRuntime, "non zero exit code: %d", exitCodeData.data)
}
// Lock again
@@ -340,7 +349,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 exitCode, lastErr
+ return exitCodeData.data, lastErr
}
// Remove the exec session from state
@@ -348,7 +357,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 exitCode, lastErr
+ return exitCodeData.data, lastErr
}
// AttachStreams contains streams that will be attached to the container