mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-20 20:44:30 +02: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{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
go term.listen(requests)
|
ready := make(chan struct{})
|
||||||
|
go term.listen(requests, ready)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Keep-Alive Ticker
|
// 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
|
return &term, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +169,8 @@ func (t *Terminal) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Negotiate terminal type and settings
|
// 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
|
hasShell := false
|
||||||
|
|
||||||
for req := range requests {
|
for req := range requests {
|
||||||
@ -172,6 +182,7 @@ func (t *Terminal) listen(requests <-chan *ssh.Request) {
|
|||||||
if !hasShell {
|
if !hasShell {
|
||||||
ok = true
|
ok = true
|
||||||
hasShell = true
|
hasShell = true
|
||||||
|
close(ready)
|
||||||
}
|
}
|
||||||
case "pty-req":
|
case "pty-req":
|
||||||
width, height, ok = parsePtyRequest(req.Payload)
|
width, height, ok = parsePtyRequest(req.Payload)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user