From a1a79c08b72793cf2f75490d8ffc844c3d16bd4a Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 1 Jul 2019 13:55:03 -0400 Subject: Implement conmon exec This includes: Implement exec -i and fix some typos in description of -i docs pass failed runtime status to caller Add resize handling for a terminal connection Customize exec systemd-cgroup slice fix healthcheck fix top add --detach-keys Implement podman-remote exec (jhonce) * Cleanup some orphaned code (jhonce) adapt remote exec for conmon exec (pehunt) Fix healthcheck and exec to match docs Introduce two new OCIRuntime errors to more comprehensively describe situations in which the runtime can error Use these different errors in branching for exit code in healthcheck and exec Set conmon to use new api version Signed-off-by: Jhon Honce Signed-off-by: Peter Hunt --- cmd/podman/exec.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'cmd/podman/exec.go') diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go index 799ed9f38..2e9b9e47e 100644 --- a/cmd/podman/exec.go +++ b/cmd/podman/exec.go @@ -35,8 +35,9 @@ func init() { execCommand.SetUsageTemplate(UsageTemplate()) flags := execCommand.Flags() flags.SetInterspersed(false) + flags.StringVar(&execCommand.DetachKeys, "detach-keys", "", "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl- where is one of: a-z, @, ^, [, , or _") flags.StringArrayVarP(&execCommand.Env, "env", "e", []string{}, "Set environment variables") - flags.BoolVarP(&execCommand.Interfactive, "interactive", "i", false, "Not supported. All exec commands are interactive by default") + flags.BoolVarP(&execCommand.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&execCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") flags.BoolVar(&execCommand.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false") flags.BoolVarP(&execCommand.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false") @@ -45,30 +46,35 @@ func init() { flags.IntVar(&execCommand.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container") flags.StringVarP(&execCommand.Workdir, "workdir", "w", "", "Working directory inside the container") markFlagHiddenForRemoteClient("latest", flags) + markFlagHiddenForRemoteClient("preserve-fds", flags) } func execCmd(c *cliconfig.ExecValues) error { - args := c.InputArgs - argStart := 1 - if len(args) < 1 && !c.Latest { - return errors.Errorf("you must provide one container name or id") - } - if len(args) < 2 && !c.Latest { - return errors.Errorf("you must provide a command to exec") - } + argLen := len(c.InputArgs) if c.Latest { - argStart = 0 + if argLen < 1 { + return errors.Errorf("you must provide a command to exec") + } + } else { + if argLen < 1 { + return errors.Errorf("you must provide one container name or id") + } + if argLen < 2 { + return errors.Errorf("you must provide a command to exec") + } } - cmd := args[argStart:] runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.DeferredShutdown(false) - err = runtime.Exec(c, cmd) - if errors.Cause(err) == define.ErrCtrStateInvalid { + 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