fix bug "" disable detach keys
fix
This patch enables `--detach-keys ""` to disable the feature. "ctrl-p, ctrl-q" will not work after this command.
@@ -444,10 +444,13 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
}
}
- keys, err := r.selectDetachKeys(c.String("detach-keys"))
+ keys := c.String("detach-keys")
+ if !c.IsSet("detach-keys") {
+ keys, err = r.selectDetachKeys(keys)
if err != nil {
return exitCode, err
}
+ }
// if the container was created as part of a pod, also start its dependencies, if any.
if err := StartAttachCtr(ctx, ctr, outputStream, errorStream, inputStream, keys, c.Bool("sig-proxy"), true, c.IsSet("pod")); err != nil {
@@ -534,10 +537,13 @@ func (r *LocalRuntime) Attach(ctx context.Context, c *cliconfig.AttachValues) er
inputStream = nil
}
- keys, err := r.selectDetachKeys(c.DetachKeys)
+ keys := c.DetachKeys
+ if !c.IsSet("detach-keys") {
+ keys, err = r.selectDetachKeys(keys)
if err != nil {
return err
}
+ }
// If the container is in a pod, also set to recursively start dependencies
if err := StartAttachCtr(ctx, ctr, os.Stdout, os.Stderr, inputStream, keys, c.SigProxy, false, ctr.PodID() != ""); err != nil && errors.Cause(err) != define.ErrDetach {
@@ -674,10 +680,13 @@ func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigP
}
}
- keys, err := r.selectDetachKeys(c.DetachKeys)
+ keys := c.DetachKeys
+ if !c.IsSet("detach-keys") {
+ keys, err = r.selectDetachKeys(keys)
if err != nil {
return exitCode, err
}
+ }
// attach to the container and also start it not already running
// If the container is in a pod, also set to recursively start dependencies
@@ -975,10 +984,13 @@ func (r *LocalRuntime) ExecContainer(ctx context.Context, cli *cliconfig.ExecVal
streams.AttachOutput = true
streams.AttachError = true
- keys, err := r.selectDetachKeys(cli.DetachKeys)
+ keys := cli.DetachKeys
+ if !cli.IsSet("detach-keys") {
+ keys, err = r.selectDetachKeys(keys)
if err != nil {
return ec, err
}
+ }
ec, err = ExecAttachCtr(ctx, ctr.Container, cli.Tty, cli.Privileged, env, cmd, cli.User, cli.Workdir, streams, uint(cli.PreserveFDs), keys)
return define.TranslateExecErrorToExitCode(ec, err), err
