mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-14 16:17:17 +03:00
Wait for shell
This commit is contained in:
parent
5dfa194ec8
commit
c0a2f32bd4
@ -108,7 +108,8 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
go term.listen(requests)
|
||||
ready := make(chan struct{})
|
||||
go term.listen(requests, ready)
|
||||
|
||||
go func() {
|
||||
// Keep-Alive Ticker
|
||||
@ -129,6 +130,14 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ready: // ok...
|
||||
case <-term.done:
|
||||
return nil, errors.New("terminal aborted")
|
||||
case <-time.NewTimer(time.Minute).C:
|
||||
return nil, errors.New("timed out starting terminal")
|
||||
}
|
||||
|
||||
return &term, nil
|
||||
}
|
||||
|
||||
@ -160,7 +169,8 @@ func (t *Terminal) Close() error {
|
||||
}
|
||||
|
||||
// Negotiate terminal type and settings
|
||||
func (t *Terminal) listen(requests <-chan *ssh.Request) {
|
||||
// ready is closed when the terminal is ready.
|
||||
func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) {
|
||||
hasShell := false
|
||||
|
||||
for req := range requests {
|
||||
@ -172,6 +182,7 @@ func (t *Terminal) listen(requests <-chan *ssh.Request) {
|
||||
if !hasShell {
|
||||
ok = true
|
||||
hasShell = true
|
||||
close(ready)
|
||||
}
|
||||
case "pty-req":
|
||||
width, height, ok = parsePtyRequest(req.Payload)
|
||||
|
Loading…
x
Reference in New Issue
Block a user