MCPcopy
hub / github.com/evilsocket/opensnitch / liveReloadWorker

Method liveReloadWorker

daemon/rule/loader.go:457–494  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

455}
456
457func (l *Loader) liveReloadWorker() {
458 l.setLiveReloadRunning(true)
459 defer l.setLiveReloadRunning(false)
460
461 log.Debug("Rules watcher started on path %s ...", l.Path)
462 if err := l.watcher.Add(l.Path); err != nil {
463 log.Error("Could not watch path: %s", err)
464 return
465 }
466
467 for {
468 select {
469 case <-l.stopLiveReload:
470 goto Exit
471 case event := <-l.watcher.Events:
472 // a new rule json file has been created or updated
473 if event.Op&fsnotify.Write == fsnotify.Write {
474 if strings.HasSuffix(event.Name, ".json") {
475 log.Important("Ruleset changed due to %s, reloading ...", path.Base(event.Name))
476 if err := l.loadRule(event.Name); err != nil {
477 log.Warning("%s", err)
478 }
479 }
480 } else if event.Op&fsnotify.Remove == fsnotify.Remove {
481 if strings.HasSuffix(event.Name, ".json") {
482 log.Important("Rule deleted %s", path.Base(event.Name))
483 // we only need to delete from memory rules of type Always,
484 // because the Remove event is of a file, i.e.: Duration == Always
485 l.deleteRule(event.Name)
486 }
487 }
488 case err := <-l.watcher.Errors:
489 log.Error("File system watcher error: %s", err)
490 }
491 }
492Exit:
493 log.Debug("[rules] liveReloadWorker() exited")
494}
495
496// FindFirstMatch will try match the connection against the existing rule set.
497func (l *Loader) FindFirstMatch(con *conman.Connection) (match *Rule) {

Callers 1

LoadMethod · 0.95

Calls 4

setLiveReloadRunningMethod · 0.95
loadRuleMethod · 0.95
deleteRuleMethod · 0.95
AddMethod · 0.45

Tested by

no test coverage detected