mirror of
https://github.com/docker/cli.git
synced 2026-01-26 15:41:42 +03:00
Simplify term signal handler.
Upstream-commit: 45543d012e98de5ed9b1e415c8ce417fe02d3c55 Component: engine
This commit is contained in:
@@ -300,7 +300,8 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||
oldState, _ := term.SaveState(cli.terminalFd)
|
||||
fmt.Fprintf(cli.out, "Password: ")
|
||||
|
||||
term.DisableEcho(cli.terminalFd, cli.out, oldState)
|
||||
term.DisableEcho(cli.terminalFd, oldState)
|
||||
|
||||
password = readInput(cli.in, cli.out)
|
||||
fmt.Fprint(cli.out, "\n")
|
||||
|
||||
@@ -1575,7 +1576,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
|
||||
})
|
||||
|
||||
if in != nil && setRawTerminal && cli.isTerminal && os.Getenv("NORAW") == "" {
|
||||
oldState, err := term.SetRawTerminal(cli.terminalFd, cli.out)
|
||||
oldState, err := term.SetRawTerminal(cli.terminalFd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -54,34 +54,33 @@ func SaveState(fd uintptr) (*State, error) {
|
||||
return &oldState, nil
|
||||
}
|
||||
|
||||
func DisableEcho(fd uintptr, out io.Writer, state *State) error {
|
||||
func DisableEcho(fd uintptr, state *State) error {
|
||||
newState := state.termios
|
||||
newState.Lflag &^= syscall.ECHO
|
||||
|
||||
HandleInterrupt(fd, out, state)
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
||||
return err
|
||||
}
|
||||
handleInterrupt(fd, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleInterrupt(fd uintptr, out io.Writer, state *State) {
|
||||
func SetRawTerminal(fd uintptr) (*State, error) {
|
||||
oldState, err := MakeRaw(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handleInterrupt(fd, oldState)
|
||||
return oldState, err
|
||||
}
|
||||
|
||||
func handleInterrupt(fd uintptr, state *State) {
|
||||
sigchan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigchan, os.Interrupt)
|
||||
|
||||
go func() {
|
||||
_ = <-sigchan
|
||||
fmt.Fprint(out, "\n")
|
||||
RestoreTerminal(fd, state)
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
|
||||
func SetRawTerminal(fd uintptr, out io.Writer) (*State, error) {
|
||||
oldState, err := MakeRaw(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
HandleInterrupt(fd, out, oldState)
|
||||
return oldState, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user