mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #14874 from vrothberg/fix-14859
exit code improvements
This commit is contained in:
@ -551,6 +551,10 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
|
|||||||
|
|
||||||
exitCode, err := c.runtime.state.GetContainerExitCode(id)
|
exitCode, err := c.runtime.state.GetContainerExitCode(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, define.ErrNoSuchExitCode) && c.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated) {
|
||||||
|
// The container never ran.
|
||||||
|
return true, 0, nil
|
||||||
|
}
|
||||||
return true, -1, err
|
return true, -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,6 +1104,12 @@ func (c *Container) cleanupRuntime(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We may be doing this redundantly for some call paths but we need to
|
||||||
|
// make sure the exit code is being read at this point.
|
||||||
|
if err := c.checkExitFile(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// If necessary, delete attach and ctl files
|
// If necessary, delete attach and ctl files
|
||||||
if err := c.removeConmonFiles(); err != nil {
|
if err := c.removeConmonFiles(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -303,7 +303,7 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
|
|||||||
ctr.state.ExitCode = -1
|
ctr.state.ExitCode = -1
|
||||||
ctr.state.FinishedTime = time.Now()
|
ctr.state.FinishedTime = time.Now()
|
||||||
ctr.state.State = define.ContainerStateExited
|
ctr.state.State = define.ContainerStateExited
|
||||||
return nil
|
return ctr.runtime.state.AddContainerExitCode(ctr.ID(), ctr.state.ExitCode)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error getting container %s state. stderr/out: %s: %w", ctr.ID(), out, err)
|
return fmt.Errorf("error getting container %s state. stderr/out: %s: %w", ctr.ID(), out, err)
|
||||||
}
|
}
|
||||||
|
@ -133,11 +133,22 @@ load helpers
|
|||||||
@test "podman kill - concurrent stop" {
|
@test "podman kill - concurrent stop" {
|
||||||
# 14761 - concurrent kill/stop must record the exit code
|
# 14761 - concurrent kill/stop must record the exit code
|
||||||
random_name=$(random_string 10)
|
random_name=$(random_string 10)
|
||||||
run_podman run -d --replace --name=$random_name alpine sh -c "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done"
|
run_podman run -d --replace --name=$random_name $IMAGE sh -c "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done"
|
||||||
$PODMAN stop -t 1 $random_name &
|
$PODMAN stop -t 1 $random_name &
|
||||||
run_podman kill $random_name
|
run_podman kill $random_name
|
||||||
run_podman wait $random_name
|
run_podman wait $random_name
|
||||||
run_podman rm -f $random_name
|
run_podman rm -f $random_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman wait - exit codes" {
|
||||||
|
random_name=$(random_string 10)
|
||||||
|
run_podman create --name=$random_name $IMAGE /no/such/command
|
||||||
|
# Container never ran -> exit code == 0
|
||||||
|
run_podman wait $random_name
|
||||||
|
# Container did not start successfully -> exit code != 0
|
||||||
|
run_podman 125 start $random_name
|
||||||
|
# FIXME(#14873): while older Podmans return 0 on wait, Docker does not.
|
||||||
|
run_podman wait $random_name
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user