зеркало из https://github.com/microsoft/docker.git
Simplify term signal handler.
This commit is contained in:
Родитель
b54ba5095b
Коммит
b8a8962833
|
@ -299,7 +299,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")
|
||||
|
||||
|
@ -1647,7 +1648,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
|
||||
}
|
||||
|
|
25
term/term.go
25
term/term.go
|
@ -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
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче