From 83ea60484c8fb139dc75b603709c17023fb3ed9b Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 14 Aug 2012 08:15:49 +0200 Subject: [PATCH] dont terminate monitor for permission-related addwatch error --- src/index/rclmonrcv.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/index/rclmonrcv.cpp b/src/index/rclmonrcv.cpp index 8cc0a7db..d0ba8752 100644 --- a/src/index/rclmonrcv.cpp +++ b/src/index/rclmonrcv.cpp @@ -33,17 +33,27 @@ * to FAM or inotify and place events on the event queue. */ -/** A small virtual interface for monitors. Probably suitable to let - either of fam/gamin or raw imonitor hide behind */ +/** A small virtual interface for monitors. Lets + * either fam/gamin or raw imonitor hide behind + */ class RclMonitor { public: - RclMonitor(){} - virtual ~RclMonitor() {} + RclMonitor() + : saved_errno(0) + { + } + + virtual ~RclMonitor() + { + } virtual bool addWatch(const string& path, bool isDir) = 0; virtual bool getEvent(RclMonEvent& ev, int msecs = -1) = 0; virtual bool ok() const = 0; // Does this monitor generate 'exist' events at startup? virtual bool generatesExist() const = 0; + + // Save significant errno after monitor calls + int saved_errno; }; // Monitor factory. We only have one compiled-in kind at a time, no @@ -94,8 +104,14 @@ public: break; } } - if (!m_mon || !m_mon->ok() || !m_mon->addWatch(fn, true)) + if (!m_mon || !m_mon->ok()) return FsTreeWalker::FtwError; + // We do nothing special if addWatch fails for a reasonable reason + if (!m_mon->addWatch(fn, true)) { + if (m_mon->saved_errno != EACCES && + m_mon->saved_errno != ENOENT) + return FsTreeWalker::FtwError; + } } else if (!m_mon->generatesExist() && flg == FsTreeWalker::FtwRegular) { // Have to synthetize events for regular files existence @@ -198,7 +214,8 @@ void *rclMonRcvRun(void *q) beaglequeuedir = path_tildexpand("~/.beagle/ToIndex/"); if (!mon->addWatch(beaglequeuedir, true)) { LOGERR(("rclMonRcvRun: addwatch (beaglequeuedit) failed\n")); - goto terminate; + if (mon->saved_errno != EACCES && mon->saved_errno != ENOENT) + goto terminate; } } } @@ -593,7 +610,9 @@ bool RclIntf::addWatch(const string& path, bool) ; int wd; if ((wd = inotify_add_watch(m_fd, path.c_str(), mask)) < 0) { - LOGERR(("RclIntf::addWatch: inotify_add_watch failed\n")); + saved_errno = errno; + LOGERR(("RclIntf::addWatch: inotify_add_watch failed. errno %d\n", + saved_errno)); return false; } m_idtopath[wd] = path;