mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
Merge pull request #16117 from alexlarsson/container-terminal-helper
Add and use libpod/Container.Terminal() helper
This commit is contained in:
@ -680,6 +680,14 @@ func (c *Container) WorkingDir() string {
|
||||
return "/"
|
||||
}
|
||||
|
||||
// Terminal returns true if the container has a terminal
|
||||
func (c *Container) Terminal() bool {
|
||||
if c.config.Spec != nil && c.config.Spec.Process != nil {
|
||||
return c.config.Spec.Process.Terminal
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// State Accessors
|
||||
// Require locking
|
||||
|
||||
|
@ -274,7 +274,7 @@ func (c *Container) Attach(streams *define.AttachStreams, keys string, resize <-
|
||||
// Send a SIGWINCH after attach succeeds so that most programs will
|
||||
// redraw the screen for the new attach session.
|
||||
attachRdy := make(chan bool, 1)
|
||||
if c.config.Spec.Process != nil && c.config.Spec.Process.Terminal {
|
||||
if c.Terminal() {
|
||||
go func() {
|
||||
<-attachRdy
|
||||
if err := c.ociRuntime.KillContainer(c, uint(signal.SIGWINCH), false); err != nil {
|
||||
|
@ -698,7 +698,7 @@ func containerToV1Container(ctx context.Context, c *Container) (v1.Container, []
|
||||
// container.EnvFromSource =
|
||||
kubeContainer.SecurityContext = kubeSec
|
||||
kubeContainer.StdinOnce = false
|
||||
kubeContainer.TTY = c.config.Spec.Process.Terminal
|
||||
kubeContainer.TTY = c.Terminal()
|
||||
|
||||
if c.config.Spec.Linux != nil &&
|
||||
c.config.Spec.Linux.Resources != nil {
|
||||
|
@ -493,10 +493,7 @@ func socketCloseWrite(conn *net.UnixConn) error {
|
||||
// Returns any errors that occurred, and whether the connection was successfully
|
||||
// hijacked before that error occurred.
|
||||
func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.ResponseWriter, streams *HTTPAttachStreams, detachKeys *string, cancel <-chan bool, hijackDone chan<- bool, streamAttach, streamLogs bool) (deferredErr error) {
|
||||
isTerminal := false
|
||||
if ctr.config.Spec.Process != nil {
|
||||
isTerminal = ctr.config.Spec.Process.Terminal
|
||||
}
|
||||
isTerminal := ctr.Terminal()
|
||||
|
||||
if streams != nil {
|
||||
if !streams.Stdin && !streams.Stdout && !streams.Stderr {
|
||||
@ -1038,7 +1035,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
|
||||
args = append(args, fmt.Sprintf("--sdnotify-socket=%s", ctr.config.SdNotifySocket))
|
||||
}
|
||||
|
||||
if ctr.config.Spec.Process.Terminal {
|
||||
if ctr.Terminal() {
|
||||
args = append(args, "-t")
|
||||
} else if ctr.config.Stdin {
|
||||
args = append(args, "-i")
|
||||
@ -1135,7 +1132,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if ctr.config.Spec.Process.Terminal {
|
||||
if ctr.Terminal() {
|
||||
cmd.Stderr = &stderrBuf
|
||||
}
|
||||
|
||||
|
@ -1690,10 +1690,8 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf := c.Config()
|
||||
if conf.Spec != nil && conf.Spec.Process != nil && conf.Spec.Process.Terminal { // if we do not pass term, running ctrs exit
|
||||
spec.Terminal = true
|
||||
}
|
||||
// if we do not pass term, running ctrs exit
|
||||
spec.Terminal = c.Terminal()
|
||||
|
||||
// Print warnings
|
||||
if len(out) > 0 {
|
||||
|
@ -49,7 +49,8 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr,
|
||||
|
||||
// Check if we are attached to a terminal. If we are, generate resize
|
||||
// events, and set the terminal to raw mode
|
||||
if haveTerminal && ctr.Spec().Process.Terminal {
|
||||
|
||||
if haveTerminal && ctr.Terminal() {
|
||||
cancel, oldTermState, err := handleTerminalAttach(ctx, resize)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user