Commit c71cc217 by Iwasaki Yudai

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.
1 parent 4b67e305
Showing with 6 additions and 5 deletions
......@@ -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()
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!