mirror of
https://github.com/containers/podman.git
synced 2025-05-18 07:36:21 +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 "/"
|
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
|
// State Accessors
|
||||||
// Require locking
|
// 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
|
// Send a SIGWINCH after attach succeeds so that most programs will
|
||||||
// redraw the screen for the new attach session.
|
// redraw the screen for the new attach session.
|
||||||
attachRdy := make(chan bool, 1)
|
attachRdy := make(chan bool, 1)
|
||||||
if c.config.Spec.Process != nil && c.config.Spec.Process.Terminal {
|
if c.Terminal() {
|
||||||
go func() {
|
go func() {
|
||||||
<-attachRdy
|
<-attachRdy
|
||||||
if err := c.ociRuntime.KillContainer(c, uint(signal.SIGWINCH), false); err != nil {
|
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 =
|
// container.EnvFromSource =
|
||||||
kubeContainer.SecurityContext = kubeSec
|
kubeContainer.SecurityContext = kubeSec
|
||||||
kubeContainer.StdinOnce = false
|
kubeContainer.StdinOnce = false
|
||||||
kubeContainer.TTY = c.config.Spec.Process.Terminal
|
kubeContainer.TTY = c.Terminal()
|
||||||
|
|
||||||
if c.config.Spec.Linux != nil &&
|
if c.config.Spec.Linux != nil &&
|
||||||
c.config.Spec.Linux.Resources != 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
|
// Returns any errors that occurred, and whether the connection was successfully
|
||||||
// hijacked before that error occurred.
|
// 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) {
|
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
|
isTerminal := ctr.Terminal()
|
||||||
if ctr.config.Spec.Process != nil {
|
|
||||||
isTerminal = ctr.config.Spec.Process.Terminal
|
|
||||||
}
|
|
||||||
|
|
||||||
if streams != nil {
|
if streams != nil {
|
||||||
if !streams.Stdin && !streams.Stdout && !streams.Stderr {
|
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))
|
args = append(args, fmt.Sprintf("--sdnotify-socket=%s", ctr.config.SdNotifySocket))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctr.config.Spec.Process.Terminal {
|
if ctr.Terminal() {
|
||||||
args = append(args, "-t")
|
args = append(args, "-t")
|
||||||
} else if ctr.config.Stdin {
|
} else if ctr.config.Stdin {
|
||||||
args = append(args, "-i")
|
args = append(args, "-i")
|
||||||
@ -1135,7 +1132,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
|
|||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if ctr.config.Spec.Process.Terminal {
|
if ctr.Terminal() {
|
||||||
cmd.Stderr = &stderrBuf
|
cmd.Stderr = &stderrBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1690,10 +1690,8 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := c.Config()
|
// if we do not pass term, running ctrs exit
|
||||||
if conf.Spec != nil && conf.Spec.Process != nil && conf.Spec.Process.Terminal { // if we do not pass term, running ctrs exit
|
spec.Terminal = c.Terminal()
|
||||||
spec.Terminal = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print warnings
|
// Print warnings
|
||||||
if len(out) > 0 {
|
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
|
// Check if we are attached to a terminal. If we are, generate resize
|
||||||
// events, and set the terminal to raw mode
|
// events, and set the terminal to raw mode
|
||||||
if haveTerminal && ctr.Spec().Process.Terminal {
|
|
||||||
|
if haveTerminal && ctr.Terminal() {
|
||||||
cancel, oldTermState, err := handleTerminalAttach(ctx, resize)
|
cancel, oldTermState, err := handleTerminalAttach(ctx, resize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user