mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-09 23:34:26 +00:00
Send SIGHUP to process after closing PTY
POSIX doesn't grantee that a blocked Read() operation will be released after closing the file. Moreover, the pty file left intact even after closing the file and the process keeps running in this case.
This commit is contained in:
parent
4b67e3059d
commit
c71cc21721
@ -73,6 +73,11 @@ func (context *clientContext) goHandleClient() {
|
||||
|
||||
<-exit
|
||||
context.pty.Close()
|
||||
|
||||
// Even if the PTY has been closed,
|
||||
// Read(0 in processSend() keeps blocking and the process doen't exit
|
||||
context.command.Process.Signal(syscall.SIGHUP)
|
||||
|
||||
context.command.Wait()
|
||||
context.connection.Close()
|
||||
log.Printf("Connection closed: %s", context.request.RemoteAddr)
|
||||
@ -95,14 +100,10 @@ func (context *clientContext) processSend() {
|
||||
return
|
||||
}
|
||||
|
||||
writer, err := context.connection.NextWriter(websocket.TextMessage)
|
||||
err = context.connection.WriteMessage(websocket.TextMessage, append([]byte{Output}, buf[:size]...))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
writer.Write([]byte{Output})
|
||||
writer.Write(buf[:size])
|
||||
writer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user