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:
Iwasaki Yudai 2015-08-28 17:22:42 +09:00
parent 4b67e3059d
commit c71cc21721

View File

@ -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()
}
}