diff --git a/.goreleaser.yml b/.goreleaser.yml index e845301..a897aa5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -88,7 +88,7 @@ archives: - submodules/**/* release: - draft: true + # draft: true # If set to auto, will mark the release as not ready for production # in case there is an indicator for this in the tag e.g. v1.0.0-rc1 diff --git a/README.md b/README.md index 9873db5..9eb255c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ Imagine being able to search your shell history based on both the command itself - :heavy_check_mark: Provide a tool to sanitize the recorded history - ## Data sanitization and analysis In order to be able to develop a good history tool I will need to get some insight into real life shell and shell history usage patterns. diff --git a/cmd/daemon/run-server.go b/cmd/daemon/run-server.go index d1a87b7..4525470 100644 --- a/cmd/daemon/run-server.go +++ b/cmd/daemon/run-server.go @@ -49,9 +49,11 @@ func runServer(config cfg.Config, reshHistoryPath, bashHistoryPath, zshHistoryPa config.SesshistInitHistorySize) // sesswatch + sesswatchRecords := make(chan records.Record) + recordSubscribers = append(recordSubscribers, sesswatchRecords) sesswatchSessionsToWatch := make(chan records.Record) - sessionInitSubscribers = append(sessionInitSubscribers, sesswatchSessionsToWatch) - sesswatch.Go(sesswatchSessionsToWatch, sessionDropSubscribers, config.SesswatchPeriodSeconds) + sessionInitSubscribers = append(sessionInitSubscribers, sesswatchRecords, sesswatchSessionsToWatch) + sesswatch.Go(sesswatchSessionsToWatch, sesswatchRecords, sessionDropSubscribers, config.SesswatchPeriodSeconds) // handlers mux := http.NewServeMux() diff --git a/pkg/sesswatch/sesswatch.go b/pkg/sesswatch/sesswatch.go index cb3d41e..ae32bc4 100644 --- a/pkg/sesswatch/sesswatch.go +++ b/pkg/sesswatch/sesswatch.go @@ -18,23 +18,37 @@ type sesswatch struct { } // Go runs the session watcher - watches sessions and sends -func Go(sessionsToWatch chan records.Record, sessionsToDrop []chan string, sleepSeconds uint) { +func Go(sessionsToWatch chan records.Record, sessionsToWatchRecords chan records.Record, sessionsToDrop []chan string, sleepSeconds uint) { sw := sesswatch{sessionsToDrop: sessionsToDrop, sleepSeconds: sleepSeconds, watchedSessions: map[string]bool{}} - go sw.waiter(sessionsToWatch) + go sw.waiter(sessionsToWatch, sessionsToWatchRecords) } -func (s *sesswatch) waiter(sessionsToWatch chan records.Record) { +func (s *sesswatch) waiter(sessionsToWatch chan records.Record, sessionsToWatchRecords chan records.Record) { for { func() { - record := <-sessionsToWatch - id := record.SessionID - pid := record.SessionPID - s.mutex.Lock() - defer s.mutex.Unlock() - if s.watchedSessions[id] == false { - log.Println("sesswatch: start watching NEW session ~ pid:", id, "~", pid) - s.watchedSessions[id] = true - go s.watcher(id, pid) + select { + case record := <-sessionsToWatch: + // normal way to start watching a session + id := record.SessionID + pid := record.SessionPID + s.mutex.Lock() + defer s.mutex.Unlock() + if s.watchedSessions[id] == false { + log.Println("sesswatch: start watching NEW session ~ pid:", id, "~", pid) + s.watchedSessions[id] = true + go s.watcher(id, pid) + } + case record := <-sessionsToWatchRecords: + // additional safety - watch sessions that were never properly initialized + id := record.SessionID + pid := record.SessionPID + s.mutex.Lock() + defer s.mutex.Unlock() + if s.watchedSessions[id] == false { + log.Println("sesswatch WARN: start watching NEW session (based on /record) ~ pid:", id, "~", pid) + s.watchedSessions[id] = true + go s.watcher(id, pid) + } } }() }