diff options
Diffstat (limited to 'cmd/podman/run.go')
-rw-r--r-- | cmd/podman/run.go | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go index 76b29cb84..64f8b6856 100644 --- a/cmd/podman/run.go +++ b/cmd/podman/run.go @@ -18,30 +18,29 @@ import ( ) var ( - runCommmand cliconfig.RunValues + runCommand cliconfig.RunValues runDescription = "Runs a command in a new container from the given image" - _runCommmand = &cobra.Command{ + _runCommand = &cobra.Command{ Use: "run", Short: "Run a command in a new container", Long: runDescription, RunE: func(cmd *cobra.Command, args []string) error { - runCommmand.InputArgs = args - runCommmand.GlobalFlags = MainGlobalOpts - return runCmd(&runCommmand) + runCommand.InputArgs = args + runCommand.GlobalFlags = MainGlobalOpts + return runCmd(&runCommand) }, Example: "IMAGE [COMMAND [ARG...]]", } ) func init() { - runCommmand.Command = _runCommmand - flags := runCommmand.Flags() + runCommand.Command = _runCommand + runCommand.SetUsageTemplate(UsageTemplate()) + flags := runCommand.Flags() flags.SetInterspersed(false) flags.Bool("sig-proxy", true, "Proxy received signals to the process (default true)") - getCreateFlags(&runCommmand.PodmanCommand) - - rootCmd.AddCommand(runCommmand.Command) + getCreateFlags(&runCommand.PodmanCommand) } func runCmd(c *cliconfig.RunValues) error { @@ -119,13 +118,21 @@ func runCmd(c *cliconfig.RunValues) error { } } if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), true); err != nil { + // We've manually detached from the container + // Do not perform cleanup, or wait for container exit code + // Just exit immediately + if errors.Cause(err) == libpod.ErrDetach { + exitCode = 0 + return nil + } + // This means the command did not exist exitCode = 127 if strings.Index(err.Error(), "permission denied") > -1 { exitCode = 126 } if c.IsSet("rm") { - if deleteError := runtime.RemoveContainer(ctx, ctr, true); deleteError != nil { + if deleteError := runtime.RemoveContainer(ctx, ctr, true, false); deleteError != nil { logrus.Errorf("unable to remove container %s after failing to start and attach to it", ctr.ID()) } } @@ -148,28 +155,12 @@ func runCmd(c *cliconfig.RunValues) error { exitCode = int(ecode) } - if createConfig.Rm { - return runtime.RemoveContainer(ctx, ctr, true) - } - - if err := ctr.Cleanup(ctx); err != nil { - // If the container has been removed already, no need to error on cleanup - // Also, if it was restarted, don't error either - if errors.Cause(err) == libpod.ErrNoSuchCtr || - errors.Cause(err) == libpod.ErrCtrRemoved || - errors.Cause(err) == libpod.ErrCtrStateInvalid { - return nil - } - - return err - } - return nil } // Read a container's exit file func readExitFile(runtimeTmp, ctrID string) (int, error) { - exitFile := filepath.Join(runtimeTmp, "exits", ctrID) + exitFile := filepath.Join(runtimeTmp, "exits", fmt.Sprintf("%s-old", ctrID)) logrus.Debugf("Attempting to read container %s exit code from file %s", ctrID, exitFile) |