summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/containers.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-07-24 13:16:21 +0200
committerGitHub <noreply@github.com>2019-07-24 13:16:21 +0200
commiteae9a009b2038d78a2cc92db740c99b1b8dc0101 (patch)
tree0bcbb02a1110495b7fb46eb4c8f3776a0849efaf /pkg/varlinkapi/containers.go
parent0d441f57d64bcca16c14ca44b7c8f35ab687ea3f (diff)
parent01a8483a59eed8bc706b5219b903704544b66c10 (diff)
downloadpodman-eae9a009b2038d78a2cc92db740c99b1b8dc0101.tar.gz
podman-eae9a009b2038d78a2cc92db740c99b1b8dc0101.tar.bz2
podman-eae9a009b2038d78a2cc92db740c99b1b8dc0101.zip
Merge pull request #3624 from haircommander/conmon-exec-with-remote-exec
Add remote exec
Diffstat (limited to 'pkg/varlinkapi/containers.go')
-rw-r--r--pkg/varlinkapi/containers.go57
1 files changed, 34 insertions, 23 deletions
diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go
index 19a8bfd2e..cd5f305c9 100644
--- a/pkg/varlinkapi/containers.go
+++ b/pkg/varlinkapi/containers.go
@@ -782,6 +782,9 @@ func (i *LibpodAPI) ExecContainer(call iopodman.VarlinkCall, opts iopodman.ExecO
fmt.Sprintf("exec requires a running container, %s is %s", ctr.ID(), state.String()))
}
+ // ACK the client upgrade request
+ call.ReplyExecContainer()
+
envs := []string{}
if opts.Env != nil {
envs = *opts.Env
@@ -797,44 +800,52 @@ func (i *LibpodAPI) ExecContainer(call iopodman.VarlinkCall, opts iopodman.ExecO
workDir = *opts.Workdir
}
+ var detachKeys string
+ if opts.DetachKeys != nil {
+ detachKeys = *opts.DetachKeys
+ }
+
resizeChan := make(chan remotecommand.TerminalSize)
- errChan := make(chan error)
reader, writer, _, pipeWriter, streams := setupStreams(call)
+ type ExitCodeError struct {
+ ExitCode uint32
+ Error error
+ }
+ ecErrChan := make(chan ExitCodeError, 1)
+
go func() {
- fmt.Printf("ExecContainer Start Reader\n")
- if err := virtwriter.Reader(reader, nil, nil, pipeWriter, resizeChan); err != nil {
- fmt.Printf("ExecContainer Reader err %s, %s\n", err.Error(), errors.Cause(err).Error())
- errChan <- err
+ if err := virtwriter.Reader(reader, nil, nil, pipeWriter, resizeChan, nil); err != nil {
+ ecErrChan <- ExitCodeError{
+ define.ExecErrorCodeGeneric,
+ err,
+ }
}
}()
- // Debugging...
- time.Sleep(5 * time.Second)
-
go func() {
- fmt.Printf("ExecContainer Start ctr.Exec\n")
- // TODO detach keys and resize
- // TODO add handling for exit code
- // TODO capture exit code and return to main thread
- _, err := ctr.Exec(opts.Tty, opts.Privileged, envs, opts.Cmd, user, workDir, streams, 0, nil, "")
+ ec, err := ctr.Exec(opts.Tty, opts.Privileged, envs, opts.Cmd, user, workDir, streams, 0, resizeChan, detachKeys)
if err != nil {
- fmt.Printf("ExecContainer Exec err %s, %s\n", err.Error(), errors.Cause(err).Error())
- errChan <- errors.Wrapf(err, "ExecContainer failed for container %s", ctr.ID())
+ logrus.Errorf(err.Error())
+ }
+ ecErrChan <- ExitCodeError{
+ uint32(ec),
+ err,
}
}()
- execErr := <-errChan
+ ecErr := <-ecErrChan
- if execErr != nil && errors.Cause(execErr) != io.EOF {
- fmt.Printf("ExecContainer err: %s\n", execErr.Error())
- return call.ReplyErrorOccurred(execErr.Error())
- }
+ exitCode := define.TranslateExecErrorToExitCode(int(ecErr.ExitCode), ecErr.Error)
- if err = virtwriter.HangUp(writer); err != nil {
- fmt.Printf("ExecContainer hangup err: %s\n", err.Error())
+ if err = virtwriter.HangUp(writer, uint32(exitCode)); err != nil {
logrus.Errorf("ExecContainer failed to HANG-UP on %s: %s", ctr.ID(), err.Error())
}
- return call.Writer.Flush()
+
+ if err := call.Writer.Flush(); err != nil {
+ logrus.Errorf("Exec Container err: %s", err.Error())
+ }
+
+ return ecErr.Error
}