summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMarco Vedovati <mvedovati@suse.com>2019-06-13 19:33:58 +0200
committerMarco Vedovati <mvedovati@suse.com>2019-06-26 10:12:34 +0200
commit7e3f1c21b060762c39139d59f73ad589a54e03fa (patch)
tree7f5277de21ca56187c1a794cc79ad0c643aaca4e /libpod
parentc9078936dd1bf5bdb59066eb1bdd179ac58f98e1 (diff)
downloadpodman-7e3f1c21b060762c39139d59f73ad589a54e03fa.tar.gz
podman-7e3f1c21b060762c39139d59f73ad589a54e03fa.tar.bz2
podman-7e3f1c21b060762c39139d59f73ad589a54e03fa.zip
libpod: specify a detach keys sequence in libpod.conf
Add the ability of specifying a detach keys sequence in libpod.conf Signed-off-by: Marco Vedovati <mvedovati@suse.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_attach_linux.go27
-rw-r--r--libpod/runtime.go7
2 files changed, 22 insertions, 12 deletions
diff --git a/libpod/container_attach_linux.go b/libpod/container_attach_linux.go
index 5293480f0..3de5ea1cf 100644
--- a/libpod/container_attach_linux.go
+++ b/libpod/container_attach_linux.go
@@ -38,29 +38,32 @@ func (c *Container) attach(streams *AttachStreams, keys string, resize <-chan re
return errors.Wrapf(define.ErrInvalidArg, "must provide at least one stream to attach to")
}
- // Check the validity of the provided keys first
- var err error
- detachKeys := []byte{}
- if len(keys) > 0 {
- detachKeys, err = term.ToBytes(keys)
- if err != nil {
- return errors.Wrapf(err, "invalid detach keys")
- }
- }
-
logrus.Debugf("Attaching to container %s", c.ID())
- return c.attachContainerSocket(resize, detachKeys, streams, startContainer, wg)
+ return c.attachContainerSocket(resize, keys, streams, startContainer, wg)
}
// attachContainerSocket connects to the container's attach socket and deals with the IO.
// wg is only required if startContainer is true
// TODO add a channel to allow interrupting
-func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSize, detachKeys []byte, streams *AttachStreams, startContainer bool, wg *sync.WaitGroup) error {
+func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSize, keys string, streams *AttachStreams, startContainer bool, wg *sync.WaitGroup) error {
if startContainer && wg == nil {
return errors.Wrapf(define.ErrInternal, "wait group not passed when startContainer set")
}
+ // Use default detach keys when keys aren't passed or specified in libpod.conf
+ if len(keys) == 0 {
+ keys = DefaultDetachKeys
+ }
+
+ // Check the validity of the provided keys
+ detachKeys := []byte{}
+ var err error
+ detachKeys, err = term.ToBytes(keys)
+ if err != nil {
+ return errors.Wrapf(err, "invalid detach keys")
+ }
+
kubeutils.HandleResizing(resize, func(size remotecommand.TerminalSize) {
controlPath := filepath.Join(c.bundlePath(), "ctl")
controlFile, err := os.OpenFile(controlPath, unix.O_WRONLY, 0)
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 152af031a..b7d6dc245 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -81,6 +81,10 @@ var (
DefaultSHMLockPath = "/libpod_lock"
// DefaultRootlessSHMLockPath is the default path for rootless SHM locks
DefaultRootlessSHMLockPath = "/libpod_rootless_lock"
+
+ // DefaultDetachKeys is the default keys sequence for detaching a
+ // container
+ DefaultDetachKeys = "ctrl-p,ctrl-q"
)
// A RuntimeOption is a functional option which alters the Runtime created by
@@ -236,6 +240,8 @@ type RuntimeConfig struct {
EventsLogger string `toml:"events_logger"`
// EventsLogFilePath is where the events log is stored.
EventsLogFilePath string `toml:-"events_logfile_path"`
+ //DetachKeys is the sequence of keys used to detach a container
+ DetachKeys string `toml:"detach_keys"`
}
// runtimeConfiguredFrom is a struct used during early runtime init to help
@@ -311,6 +317,7 @@ func defaultRuntimeConfig() (RuntimeConfig, error) {
EnableLabeling: true,
NumLocks: 2048,
EventsLogger: events.DefaultEventerType.String(),
+ DetachKeys: DefaultDetachKeys,
}, nil
}