From 89dd2259102f59ce5f36c75ddcdfe628cc09bff4 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Sun, 20 May 2018 14:48:24 -0700 Subject: [PATCH] Experiment - moved sigwinch goroutine out of main client --- hkexsh/hkexsh.go | 26 +------------------------- hkexsh/termsize_linux.go | 38 ++++++++++++++++++++++++++++++++++++++ hkexsh/termsize_win.go | 8 ++++++++ 3 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 hkexsh/termsize_linux.go create mode 100644 hkexsh/termsize_win.go diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 1aaa95c..9b7bf2f 100644 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -15,12 +15,10 @@ import ( "log" "os" "os/exec" - "os/signal" "os/user" "runtime" "strings" "sync" - "syscall" hkexsh "blitter.com/go/hkexsh" isatty "github.com/mattn/go-isatty" @@ -113,9 +111,6 @@ func main() { defer conn.Close() // From this point on, conn is a secure encrypted channel - rows := 0 - cols := 0 - // Set stdin in raw mode if it's an interactive session // TODO: send flag to server side indicating this // affects shell command used @@ -223,26 +218,7 @@ func main() { }() if isInteractive { - // Handle pty resizes (notify server side) - ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGWINCH) - wg.Add(1) - go func() { - defer wg.Done() - - for range ch { - // Query client's term size so we can communicate it to server - // pty after interactive session starts - rows, cols, err = getTermSize() - log.Printf("[rows %v cols %v]\n", rows, cols) - if err != nil { - panic(err) - } - termSzPacket := fmt.Sprintf("%d %d", rows, cols) - conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize) - } - }() - ch <- syscall.SIGWINCH // Initial resize. + handleTermResizes() // client writer (to server) goroutine wg.Add(1) diff --git a/hkexsh/termsize_linux.go b/hkexsh/termsize_linux.go new file mode 100644 index 0000000..5084fa1 --- /dev/null +++ b/hkexsh/termsize_linux.go @@ -0,0 +1,38 @@ +// +build linux +package main + +import ( + "fmt" + "log" + "os" + "os/signal" + "syscall" + + hkexsh "blitter.com/go/hkexsh" +) + +// Handle pty resizes (notify server side) +func handleTermResizes() { + rows := 0 + cols := 0 + + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGWINCH) + wg.Add(1) + go func() { + defer wg.Done() + + for range ch { + // Query client's term size so we can communicate it to server + // pty after interactive session starts + rows, cols, err = getTermSize() + log.Printf("[rows %v cols %v]\n", rows, cols) + if err != nil { + panic(err) + } + termSzPacket := fmt.Sprintf("%d %d", rows, cols) + conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize) + } + }() + ch <- syscall.SIGWINCH // Initial resize. +} diff --git a/hkexsh/termsize_win.go b/hkexsh/termsize_win.go new file mode 100644 index 0000000..b1ae088 --- /dev/null +++ b/hkexsh/termsize_win.go @@ -0,0 +1,8 @@ +// +build windows +package main + +// Handle pty resizes (notify server side) +func handleTermResizes() { +} + +