Ensure Session.Exit can only be called once
This commit is contained in:
parent
7bc24bc5e0
commit
71d4b985d1
@ -2,6 +2,7 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ type session struct {
|
|||||||
conn *gossh.ServerConn
|
conn *gossh.ServerConn
|
||||||
handler Handler
|
handler Handler
|
||||||
handled bool
|
handled bool
|
||||||
|
exited bool
|
||||||
pty *Pty
|
pty *Pty
|
||||||
winch chan Window
|
winch chan Window
|
||||||
env []string
|
env []string
|
||||||
@ -86,6 +88,11 @@ func (sess *session) PublicKey() PublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sess *session) Exit(code int) error {
|
func (sess *session) Exit(code int) error {
|
||||||
|
if sess.exited {
|
||||||
|
return errors.New("Session.Exit called multiple times")
|
||||||
|
}
|
||||||
|
sess.exited = true
|
||||||
|
|
||||||
status := struct{ Status uint32 }{uint32(code)}
|
status := struct{ Status uint32 }{uint32(code)}
|
||||||
_, err := sess.SendRequest("exit-status", false, gossh.Marshal(&status))
|
_, err := sess.SendRequest("exit-status", false, gossh.Marshal(&status))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user