init session when resh updates, cleanup

pull/30/head
Simon Let 6 years ago
parent aba197561a
commit 963fd9e972
  1. 2
      cmd/daemon/run-server.go
  2. 4
      pkg/histlist/histlist.go
  3. 17
      pkg/sesshist/sesshist.go

@ -37,7 +37,7 @@ func runServer(config cfg.Config, reshHistoryPath, bashHistoryPath, zshHistoryPa
histfileSignals := make(chan os.Signal)
signalSubscribers = append(signalSubscribers, histfileSignals)
maxHistSize := 10000 // lines
minHistSizeKB := 100 // roughly lines
minHistSizeKB := 2000 // roughly lines
histfileBox := histfile.New(histfileRecords, histfileSessionsToDrop,
reshHistoryPath, bashHistoryPath, zshHistoryPath,
maxHistSize, minHistSizeKB,

@ -30,7 +30,7 @@ func Copy(hl Histlist) Histlist {
// AddCmdLine to the histlist
func (h *Histlist) AddCmdLine(cmdLine string) {
lenBefore := len(h.List)
// lenBefore := len(h.List)
// lookup
idx, found := h.LastIndex[cmdLine]
if found {
@ -53,7 +53,7 @@ func (h *Histlist) AddCmdLine(cmdLine string) {
h.LastIndex[cmdLine] = len(h.List)
// append new cmdline
h.List = append(h.List, cmdLine)
log.Println("histlist: Added cmdLine:", cmdLine, "; history length:", lenBefore, "->", len(h.List))
// log.Println("histlist: Added cmdLine:", cmdLine, "; history length:", lenBefore, "->", len(h.List))
}
// AddHistlist contents of another histlist to this histlist

@ -58,13 +58,28 @@ func (s *Dispatch) recordAdder(recordsToAdd chan records.Record) {
if record.PartOne {
log.Println("sesshist: got record to add - " + record.CmdLine)
s.addRecentRecord(record.SessionID, record)
} else {
// this inits session on RESH update
s.checkSession(record.SessionID, record.Shell)
}
// TODO: we will need to handle part2 as well eventually
}
}
func (s *Dispatch) checkSession(sessionID, shell string) {
s.mutex.RLock()
_, found := s.sessions[sessionID]
s.mutex.RUnlock()
if found == false {
err := s.initSession(sessionID, shell)
if err != nil {
log.Println("sesshist: Error while checking session:", err)
}
}
}
// InitSession struct
func (s *Dispatch) initSession(sessionID string, shell string) error {
func (s *Dispatch) initSession(sessionID, shell string) error {
log.Println("sesshist: initializing session - " + sessionID)
s.mutex.RLock()
_, found := s.sessions[sessionID]

Loading…
Cancel
Save