tty: clean up epollConsole closing
ec0d23a92f
("tty: close epollConsole on errors") fixed a significant
issue, but the cleanup was not ideal (especially if the function is
changed in future to add additional error conditions to those currently
present). Using the defer-named-error trick avoids this issue and makes
the code more readable.
Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
00dc70017d
commit
5de99cd390
9
tty.go
9
tty.go
|
@ -71,7 +71,7 @@ func inheritStdio(process *libcontainer.Process) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
|
||||
func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) (Err error) {
|
||||
f, err := utils.RecvFd(socket)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -89,6 +89,11 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if Err != nil {
|
||||
epollConsole.Close()
|
||||
}
|
||||
}()
|
||||
go epoller.Wait()
|
||||
go io.Copy(epollConsole, os.Stdin)
|
||||
t.wg.Add(1)
|
||||
|
@ -97,11 +102,9 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
|
|||
// set raw mode to stdin and also handle interrupt
|
||||
stdin, err := console.ConsoleFromFile(os.Stdin)
|
||||
if err != nil {
|
||||
epollConsole.Close()
|
||||
return err
|
||||
}
|
||||
if err := stdin.SetRaw(); err != nil {
|
||||
epollConsole.Close()
|
||||
return fmt.Errorf("failed to set the terminal from the stdin: %v", err)
|
||||
}
|
||||
go handleInterrupt(stdin)
|
||||
|
|
Loading…
Reference in New Issue