diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2019-09-07 05:47:05 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2019-09-12 16:20:01 -0400 |
commit | 82ac0d8925dbb5aa738f1494ecb002eb6daca992 (patch) | |
tree | fcb1d2961f223806b228e7c930bc134fc9f0f7fd /pkg/varlinkapi/attach.go | |
parent | 535111b5d5cfa0d203df77e6d6b0b69eda46bb82 (diff) | |
download | podman-82ac0d8925dbb5aa738f1494ecb002eb6daca992.tar.gz podman-82ac0d8925dbb5aa738f1494ecb002eb6daca992.tar.bz2 podman-82ac0d8925dbb5aa738f1494ecb002eb6daca992.zip |
Podman-remote run should wait for exit code
This change matches what is happening on the podman local side
and should eliminate a race condition.
Also exit commands on the server side should start to return to client.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/varlinkapi/attach.go')
-rw-r--r-- | pkg/varlinkapi/attach.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/pkg/varlinkapi/attach.go b/pkg/varlinkapi/attach.go index 1f8d48eb9..3bd487849 100644 --- a/pkg/varlinkapi/attach.go +++ b/pkg/varlinkapi/attach.go @@ -9,7 +9,9 @@ import ( "github.com/containers/libpod/cmd/podman/varlink" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/libpod/events" "github.com/containers/libpod/pkg/varlinkapi/virtwriter" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/client-go/tools/remotecommand" ) @@ -79,11 +81,36 @@ func (i *LibpodAPI) Attach(call iopodman.VarlinkCall, name string, detachKeys st finalErr = startAndAttach(ctr, streams, detachKeys, resize, errChan) } + exitCode := define.ExitCode(finalErr) if finalErr != define.ErrDetach && finalErr != nil { logrus.Error(finalErr) + } else { + if ecode, err := ctr.Wait(); err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + // Check events + event, err := i.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited) + if err != nil { + logrus.Errorf("Cannot get exit code: %v", err) + exitCode = define.ExecErrorCodeNotFound + } else { + exitCode = event.ContainerExitCode + } + } else { + exitCode = define.ExitCode(err) + } + } else { + exitCode = int(ecode) + } + } + + if ctr.AutoRemove() { + err := i.Runtime.RemoveContainer(getContext(), ctr, false, false) + if err != nil { + logrus.Errorf("Failed to remove container %s: %s", ctr.ID(), err.Error()) + } } - if err = virtwriter.HangUp(writer, 0); err != nil { + if err = virtwriter.HangUp(writer, uint32(exitCode)); err != nil { logrus.Errorf("Failed to HANG-UP attach to %s: %s", ctr.ID(), err.Error()) } return call.Writer.Flush() |