From 71d4b985d1430d4bcce2ce51112d924098291991 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Fri, 3 Feb 2017 15:57:30 -0800 Subject: [PATCH] Ensure Session.Exit can only be called once --- session.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/session.go b/session.go index 79c313e..cb59240 100644 --- a/session.go +++ b/session.go @@ -2,6 +2,7 @@ package ssh import ( "bytes" + "errors" "fmt" "net" @@ -54,6 +55,7 @@ type session struct { conn *gossh.ServerConn handler Handler handled bool + exited bool pty *Pty winch chan Window env []string @@ -86,6 +88,11 @@ func (sess *session) PublicKey() PublicKey { } 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)} _, err := sess.SendRequest("exit-status", false, gossh.Marshal(&status)) if err != nil {