From 5ac07b20f6c0c211f8791e0353e5dab739a397b1 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 1 Aug 2011 13:59:01 +0200 Subject: [PATCH] rt monitor: make a copy of the config in the 2nd thread to avoid concurrent accesses (no reported bug on this, but could lead to a crash) --- src/index/rclmonrcv.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/index/rclmonrcv.cpp b/src/index/rclmonrcv.cpp index 2adfd045..abf96947 100644 --- a/src/index/rclmonrcv.cpp +++ b/src/index/rclmonrcv.cpp @@ -128,8 +128,13 @@ void *rclMonRcvRun(void *q) return 0; } + // Make a local copy of the configuration as it doesn't like + // concurrent accesses. It's ok to copy it here as the other + // thread will not work before we have sent events. + RclConfig lconfig(*queue->getConfig()); + // Get top directories from config - list tdl = queue->getConfig()->getTopdirs(); + list tdl = lconfig.getTopdirs(); if (tdl.empty()) { LOGERR(("rclMonRcvRun:: top directory list (topdirs param.) not" "found in config or Directory list parse error")); @@ -139,13 +144,13 @@ void *rclMonRcvRun(void *q) // Walk the directory trees to add watches FsTreeWalker walker; - walker.setSkippedPaths(queue->getConfig()->getDaemSkippedPaths()); - WalkCB walkcb(queue->getConfig(), mon, queue, walker); + walker.setSkippedPaths(lconfig.getDaemSkippedPaths()); + WalkCB walkcb(&lconfig, mon, queue, walker); for (list::iterator it = tdl.begin(); it != tdl.end(); it++) { - queue->getConfig()->setKeyDir(*it); + lconfig.setKeyDir(*it); // Adjust the follow symlinks options bool follow; - if (queue->getConfig()->getConfParam("followLinks", &follow) && + if (lconfig.getConfParam("followLinks", &follow) && follow) { walker.setOpts(FsTreeWalker::FtwFollow); } else { @@ -156,10 +161,10 @@ void *rclMonRcvRun(void *q) } bool dobeagle = false; - queue->getConfig()->getConfParam("processbeaglequeue", &dobeagle); + lconfig.getConfParam("processbeaglequeue", &dobeagle); if (dobeagle) { string beaglequeuedir; - if (!queue->getConfig()->getConfParam("beaglequeuedir", beaglequeuedir)) + if (!lconfig.getConfParam("beaglequeuedir", beaglequeuedir)) beaglequeuedir = path_tildexpand("~/.beagle/ToIndex/"); mon->addWatch(beaglequeuedir, true); }