From 75f46957f0116584881497fb02d60d836f03a1a5 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Mon, 16 Dec 2019 17:20:19 +0100 Subject: [PATCH] add debug conf, fix minor sesshist request issue, fixes --- Makefile | 4 +++- cmd/daemon/main.go | 4 ++++ cmd/daemon/recall.go | 24 +++++++++++++++++------- cmd/postcollect/main.go | 2 ++ conf/config-dev.toml | 6 ++++++ scripts/hooks.sh | 5 ++++- 6 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 conf/config-dev.toml diff --git a/Makefile b/Makefile index f48198c..5917e2c 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,10 @@ sanitize: build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bin/resh-daemon\ bin/resh-evaluate bin/resh-sanitize bin/resh-control bin/resh-config bin/resh-inspect -install: build +install: build conf/config-dev.toml scripts/install.sh + # Dev config + cp -f conf/config-dev.toml ~/.config/ test_go: # Running tests diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go index 56ff608..67ff515 100644 --- a/cmd/daemon/main.go +++ b/cmd/daemon/main.go @@ -23,6 +23,9 @@ var version string // commit from git set during build var commit string +// Debug switch +var Debug = false + func main() { log.Println("Daemon starting... \n" + "version: " + version + @@ -51,6 +54,7 @@ func main() { return } if config.Debug { + Debug = true log.SetFlags(log.LstdFlags | log.Lmicroseconds) } diff --git a/cmd/daemon/recall.go b/cmd/daemon/recall.go index 32e63aa..930537c 100644 --- a/cmd/daemon/recall.go +++ b/cmd/daemon/recall.go @@ -17,8 +17,10 @@ type recallHandler struct { } func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - log.Println("/recall START") - log.Println("/recall reading body ...") + if Debug { + log.Println("/recall START") + log.Println("/recall reading body ...") + } jsn, err := ioutil.ReadAll(r.Body) if err != nil { log.Println("Error reading the body", err) @@ -26,14 +28,18 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } rec := records.SlimRecord{} - log.Println("/recall unmarshaling record ...") + if Debug { + log.Println("/recall unmarshaling record ...") + } err = json.Unmarshal(jsn, &rec) if err != nil { log.Println("Decoding error:", err) log.Println("Payload:", jsn) return } - log.Println("/recall recalling ...") + if Debug { + log.Println("/recall recalling ...") + } found := true cmd, err := h.sesshistDispatch.Recall(rec.SessionID, rec.RecallHistno, rec.RecallPrefix) if err != nil { @@ -43,15 +49,19 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { cmd = "" } resp := collect.SingleResponse{CmdLine: cmd, Found: found} - log.Println("/recall marshaling response ...") + if Debug { + log.Println("/recall marshaling response ...") + } jsn, err = json.Marshal(&resp) if err != nil { log.Println("Encoding error:", err) log.Println("Response:", resp) return } - log.Println(string(jsn)) - log.Println("/recall writing response ...") + if Debug { + log.Println(string(jsn)) + log.Println("/recall writing response ...") + } w.Write(jsn) log.Println("/recall END - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ", cmd, " (found:", found, ")") } diff --git a/cmd/postcollect/main.go b/cmd/postcollect/main.go index f343834..d987bc5 100644 --- a/cmd/postcollect/main.go +++ b/cmd/postcollect/main.go @@ -45,6 +45,7 @@ func main() { exitCode := flag.Int("exitCode", -1, "exit code") sessionID := flag.String("sessionId", "", "resh generated session id") shlvl := flag.Int("shlvl", -1, "$SHLVL") + shell := flag.String("shell", "", "actual shell") // posix variables pwdAfter := flag.String("pwdAfter", "", "$PWD after command") @@ -118,6 +119,7 @@ func main() { ExitCode: *exitCode, SessionID: *sessionID, Shlvl: *shlvl, + Shell: *shell, PwdAfter: *pwdAfter, diff --git a/conf/config-dev.toml b/conf/config-dev.toml new file mode 100644 index 0000000..7dc647c --- /dev/null +++ b/conf/config-dev.toml @@ -0,0 +1,6 @@ +port = 2627 +sesswatchPeriodSeconds = 120 +sesshistInitHistorySize = 1000 +debug = true +bindArrowKeysBash = false +bindArrowKeysZsh = true diff --git a/scripts/hooks.sh b/scripts/hooks.sh index 20f5935..3d57b07 100644 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -3,7 +3,9 @@ __resh_reset_variables() { __RESH_HISTNO=0 __RESH_HISTNO_MAX="" __RESH_HISTNO_ZERO_LINE="" - __RESH_HIST_PREV_LINE="" + __RESH_HIST_PREV_LINE="" # deprecated + __RESH_HIST_PREV_CURSOR="" # deprecated + __RESH_HIST_PREV_PREFIX="" __RESH_HIST_RECALL_ACTIONS="" __RESH_HIST_NO_PREFIX_MODE=0 __RESH_HIST_RECALL_STRATEGY="" @@ -148,6 +150,7 @@ __resh_precmd() { -realtimeBefore "$__RESH_RT_BEFORE" \ -exitCode "$__RESH_EXIT_CODE" \ -sessionId "$__RESH_SESSION_ID" \ + -shell "$__RESH_SHELL" \ -shlvl "$__RESH_SHLVL" \ -pwdAfter "$__RESH_PWD_AFTER" \ -gitCdupAfter "$__RESH_GIT_CDUP_AFTER" \