terminal: fix deadlock with finer-grained locking
Commit 1bac87e804
("terminal: fix race when closing a terminal") fixed
a race in Terminal.Draw by using a mutex. The current locking of the
entire Draw function could create a deadlock, however, since this
function itself might call Terminal.Close which is protected by the same
mutex. A finer-grained locking solves both the race and deadlock
problem.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
0cc992b4e3
commit
57bd9e318b
|
@ -232,9 +232,6 @@ func (term *Terminal) invalidate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) Draw(ctx *ui.Context) {
|
func (term *Terminal) Draw(ctx *ui.Context) {
|
||||||
term.closeMutex.Lock()
|
|
||||||
defer term.closeMutex.Unlock()
|
|
||||||
|
|
||||||
if term.destroyed {
|
if term.destroyed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -252,7 +249,15 @@ func (term *Terminal) Draw(ctx *ui.Context) {
|
||||||
|
|
||||||
if term.pty == nil {
|
if term.pty == nil {
|
||||||
term.vterm.SetSize(ctx.Height(), ctx.Width())
|
term.vterm.SetSize(ctx.Height(), ctx.Width())
|
||||||
|
|
||||||
|
term.closeMutex.Lock()
|
||||||
|
if term.cmd == nil {
|
||||||
|
term.closeMutex.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
tty, err := pty.StartWithAttrs(term.cmd, &winsize, &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1})
|
tty, err := pty.StartWithAttrs(term.cmd, &winsize, &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1})
|
||||||
|
term.closeMutex.Unlock()
|
||||||
|
|
||||||
term.pty = tty
|
term.pty = tty
|
||||||
if err != nil {
|
if err != nil {
|
||||||
term.Close(err)
|
term.Close(err)
|
||||||
|
|
Loading…
Reference in New Issue