From 479eeac62cd74e32cbe74fc8afbfc82d4d8a8abd Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 22 Jul 2019 15:12:29 -0400 Subject: move editing of exitCode to runtime There's no way to get the error if we successfully get an exit code (as it's just printed to stderr instead). instead of relying on the error to be passed to podman, and edit based on the error code, process it on the varlink side instead Also move error codes to define package Signed-off-by: Peter Hunt --- cmd/podman/exec.go | 7 ------- 1 file changed, 7 deletions(-) (limited to 'cmd/podman') diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go index 2e9b9e47e..649a7b0db 100644 --- a/cmd/podman/exec.go +++ b/cmd/podman/exec.go @@ -2,7 +2,6 @@ package main import ( "github.com/containers/libpod/cmd/podman/cliconfig" - "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/adapter" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -70,11 +69,5 @@ func execCmd(c *cliconfig.ExecValues) error { defer runtime.DeferredShutdown(false) exitCode, err = runtime.ExecContainer(getContext(), c) - if errors.Cause(err) == define.ErrOCIRuntimePermissionDenied { - exitCode = 126 - } - if errors.Cause(err) == define.ErrOCIRuntimeNotFound { - exitCode = 127 - } return err } -- cgit v1.2.3-54-g00ecf From 5bf99a82ff48cd5097182c55fe1347daf793324b Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 22 Jul 2019 15:56:58 -0400 Subject: add detach keys support for remote Signed-off-by: Peter Hunt --- API.md | 2 ++ cmd/podman/varlink/io.podman.varlink | 4 +++- pkg/adapter/containers_remote.go | 2 +- pkg/varlinkapi/containers.go | 15 ++++++++++----- test/e2e/exec_test.go | 4 +--- 5 files changed, 17 insertions(+), 10 deletions(-) (limited to 'cmd/podman') diff --git a/API.md b/API.md index 31bffeb16..71d09fed8 100755 --- a/API.md +++ b/API.md @@ -1591,6 +1591,8 @@ user [?string](#?string) workdir [?string](#?string) env [?[]string](#?[]string) + +detachKeys [?string](#?string) ### type Image diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink index cc66e7df0..f5f3250f7 100644 --- a/cmd/podman/varlink/io.podman.varlink +++ b/cmd/podman/varlink/io.podman.varlink @@ -514,7 +514,9 @@ type ExecOpts( # workdir to run command in container workdir: ?string, # slice of keyword=value environment variables - env: ?[]string + env: ?[]string, + # string of detach keys + detachKeys: ?string ) # GetVersion returns version and build information of the podman service diff --git a/pkg/adapter/containers_remote.go b/pkg/adapter/containers_remote.go index 7fce30378..3b1b80315 100644 --- a/pkg/adapter/containers_remote.go +++ b/pkg/adapter/containers_remote.go @@ -1017,7 +1017,6 @@ func (r *LocalRuntime) ExecContainer(ctx context.Context, cli *cliconfig.ExecVal // Check if we are attached to a terminal. If we are, generate resize // events, and set the terminal to raw mode - // TODO FIXME tty if haveTerminal && cli.Tty { cancel, oldTermState, err := handleTerminalAttach(ctx, resize) if err != nil { @@ -1038,6 +1037,7 @@ func (r *LocalRuntime) ExecContainer(ctx context.Context, cli *cliconfig.ExecVal User: &cli.User, Workdir: &cli.Workdir, Env: &envs, + DetachKeys: &cli.DetachKeys, } inputStream := os.Stdin diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go index fa17bed84..97eb36014 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 @@ -796,8 +799,11 @@ func (i *LibpodAPI) ExecContainer(call iopodman.VarlinkCall, opts iopodman.ExecO if opts.Workdir != nil { workDir = *opts.Workdir } - // ACK the client upgrade request - call.ReplyExecContainer() + + var detachKeys string + if opts.DetachKeys != nil { + detachKeys = *opts.DetachKeys + } resizeChan := make(chan remotecommand.TerminalSize) @@ -818,11 +824,10 @@ func (i *LibpodAPI) ExecContainer(call iopodman.VarlinkCall, opts iopodman.ExecO } }() - // TODO FIXME detach keys go func() { - ec, err := ctr.Exec(opts.Tty, opts.Privileged, envs, opts.Cmd, user, workDir, streams, 0, resizeChan, "") + ec, err := ctr.Exec(opts.Tty, opts.Privileged, envs, opts.Cmd, user, workDir, streams, 0, resizeChan, detachKeys) if err != nil { - logrus.Errorf("ExecContainer Exec err %s, %s\n", err.Error(), errors.Cause(err).Error()) + logrus.Errorf(err.Error()) } ecErrChan <- ExitCodeError{ uint32(ec), diff --git a/test/e2e/exec_test.go b/test/e2e/exec_test.go index bd4fb7aad..6cf78a25c 100644 --- a/test/e2e/exec_test.go +++ b/test/e2e/exec_test.go @@ -77,8 +77,6 @@ var _ = Describe("Podman exec", func() { }) It("podman exec environment test", func() { - // passing environment variables is not supported in the remote client - SkipIfRemote() setup := podmanTest.RunTopContainer("test1") setup.WaitWithDefaultTimeout() Expect(setup.ExitCode()).To(Equal(0)) @@ -110,8 +108,8 @@ var _ = Describe("Podman exec", func() { match, _ := session.GrepString("BAR") Expect(match).Should(BeTrue()) os.Unsetenv("FOO") - }) + It("podman exec exit code", func() { setup := podmanTest.RunTopContainer("test1") setup.WaitWithDefaultTimeout() -- cgit v1.2.3-54-g00ecf