mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Retrieve exit codes for containers via events
As we previously removed our exit code retrieval code to stop a memory leak, we need a new way of doing this. Fortunately, events is able to do the job for us. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/shared/parse"
|
"github.com/containers/libpod/cmd/podman/shared/parse"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
|
"github.com/containers/libpod/libpod/events"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
"github.com/containers/libpod/libpod/logs"
|
"github.com/containers/libpod/libpod/logs"
|
||||||
"github.com/containers/libpod/pkg/adapter/shortcuts"
|
"github.com/containers/libpod/pkg/adapter/shortcuts"
|
||||||
@ -417,8 +418,14 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
|
|||||||
|
|
||||||
if ecode, err := ctr.Wait(); err != nil {
|
if ecode, err := ctr.Wait(); err != nil {
|
||||||
if errors.Cause(err) == define.ErrNoSuchCtr {
|
if errors.Cause(err) == define.ErrNoSuchCtr {
|
||||||
logrus.Errorf("Cannot get exit code: %v", err)
|
// Check events
|
||||||
exitCode = 127
|
event, err := r.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Cannot get exit code: %v", err)
|
||||||
|
exitCode = 127
|
||||||
|
} else {
|
||||||
|
exitCode = event.ContainerExitCode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exitCode = int(ecode)
|
exitCode = int(ecode)
|
||||||
@ -622,8 +629,14 @@ func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigP
|
|||||||
|
|
||||||
if ecode, err := ctr.Wait(); err != nil {
|
if ecode, err := ctr.Wait(); err != nil {
|
||||||
if errors.Cause(err) == define.ErrNoSuchCtr {
|
if errors.Cause(err) == define.ErrNoSuchCtr {
|
||||||
logrus.Errorf("Cannot get exit code: %v", err)
|
// Check events
|
||||||
exitCode = 127
|
event, err := r.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Cannot get exit code: %v", err)
|
||||||
|
exitCode = 127
|
||||||
|
} else {
|
||||||
|
exitCode = event.ContainerExitCode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exitCode = int(ecode)
|
exitCode = int(ecode)
|
||||||
|
Reference in New Issue
Block a user