summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-08-05 13:48:01 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-08-05 14:30:48 -0400
commit7a64ce35db378e69b813aab7f026f11fbaf7e7f9 (patch)
tree7c970458b233ca5760425a8502ba459e4855f1ac /libpod
parent7a15be546adffe4f884abfbd4ed02f69ac7659e0 (diff)
downloadpodman-7a64ce35db378e69b813aab7f026f11fbaf7e7f9.tar.gz
podman-7a64ce35db378e69b813aab7f026f11fbaf7e7f9.tar.bz2
podman-7a64ce35db378e69b813aab7f026f11fbaf7e7f9.zip
Ensure that exec errors write exit codes to the DB
In local Podman, the frontend interprets the error and exit code given by the Exec API to determine the appropriate exit code to set for Podman itself; special cases like a missing executable receive special exit codes. Exec for the remote API, however, has to do this inside Libpod itself, as Libpod will be directly queried (via the Inspect API for exec sessions) to get the exit code. This was done correctly when the exec session started properly, but we did not properly handle cases where the OCI runtime fails before the exec session can properly start. Making two error returns that would otherwise not set exit code actually do so should resolve the issue. Fixes #6893 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_exec.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/libpod/container_exec.go b/libpod/container_exec.go
index 08e95e6dd..bfeae0a11 100644
--- a/libpod/container_exec.go
+++ b/libpod/container_exec.go
@@ -415,6 +415,13 @@ func (c *Container) ExecHTTPStartAndAttach(sessionID string, httpCon net.Conn, h
execOpts, err := prepareForExec(c, session)
if err != nil {
+ session.State = define.ExecStateStopped
+ session.ExitCode = define.ExecErrorCodeGeneric
+
+ if err := c.save(); err != nil {
+ logrus.Errorf("Error saving container %s exec session %s after failure to prepare: %v", err, c.ID(), session.ID())
+ }
+
return err
}
@@ -427,6 +434,13 @@ func (c *Container) ExecHTTPStartAndAttach(sessionID string, httpCon net.Conn, h
pid, attachChan, err := c.ociRuntime.ExecContainerHTTP(c, session.ID(), execOpts, httpCon, httpBuf, streams, cancel)
if err != nil {
+ session.State = define.ExecStateStopped
+ session.ExitCode = define.TranslateExecErrorToExitCode(define.ExecErrorCodeGeneric, err)
+
+ if err := c.save(); err != nil {
+ logrus.Errorf("Error saving container %s exec session %s after failure to start: %v", err, c.ID(), session.ID())
+ }
+
return err
}