Skip to content

Commit

Permalink
Merge pull request #14874 from vrothberg/fix-14859
Browse files Browse the repository at this point in the history
exit code improvements
  • Loading branch information
openshift-ci[bot] authored Jul 11, 2022
2 parents 0af75a7 + 3bb4cf8 commit ea2c31c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)

exitCode, err := c.runtime.state.GetContainerExitCode(id)
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
}

Expand Down
6 changes: 6 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,12 @@ func (c *Container) cleanupRuntime(ctx context.Context) error {
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 err := c.removeConmonFiles(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
ctr.state.ExitCode = -1
ctr.state.FinishedTime = time.Now()
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)
}
Expand Down
13 changes: 12 additions & 1 deletion test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,22 @@ load helpers
@test "podman kill - concurrent stop" {
# 14761 - concurrent kill/stop must record the exit code
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 &
run_podman kill $random_name
run_podman wait $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

0 comments on commit ea2c31c

Please sign in to comment.