From 8a24fb113f2668980012fcb748ee2dc4e30cf57a Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Thu, 6 Sep 2018 11:40:13 -0700 Subject: [PATCH] client prints nonzero remote end exit status; comment cleanup --- hkexsh/hkexsh.go | 6 ++++++ hkexshd/hkexshd.go | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 15d2124..80c9e56 100755 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -241,6 +241,9 @@ func doShellMode(isInteractive bool, conn *hkexnet.Conn, oldState *hkexsh.State, _, inerr := io.Copy(os.Stdout, conn) if inerr != nil { _ = hkexsh.Restore(int(os.Stdin.Fd()), oldState) // Best effort. + // Copy operations and user logging off will cause + // a "use of closed network connection" so handle that + // gracefully here if !strings.HasSuffix(inerr.Error(), "use of closed network connection") { log.Println(inerr) os.Exit(1) @@ -545,5 +548,8 @@ func main() { _ = hkexsh.Restore(int(os.Stdin.Fd()), oldState) // Best effort. } + if rec.status != 0 { + fmt.Fprintln(os.Stderr, "Remote end exited with status:", rec.status) + } os.Exit(rec.status) } diff --git a/hkexshd/hkexshd.go b/hkexshd/hkexshd.go index 8d12527..6255c00 100755 --- a/hkexshd/hkexshd.go +++ b/hkexshd/hkexshd.go @@ -315,8 +315,8 @@ func runShellAs(who string, cmd string, interactive bool, conn hkexnet.Conn, cha exitStatus = status.ExitStatus() log.Printf("Exit Status: %d", exitStatus) } - } - conn.SetStatus(uint8(exitStatus)) + } + conn.SetStatus(uint8(exitStatus)) } wg.Wait() // Wait on pty->stdout completion to client } @@ -530,7 +530,7 @@ func main() { } hc.SetStatus(uint8(cmdStatus)) // Signal other end transfer is complete - hc.WritePacket([]byte{byte(/*255*/cmdStatus)}, hkexnet.CSOExitStatus) + hc.WritePacket([]byte{byte( /*255*/ cmdStatus)}, hkexnet.CSOExitStatus) //fmt.Println("Waiting for EOF from other end.") _, _ = hc.Read(nil /*ackByte*/) //fmt.Println("Got remote end ack.")