summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/FileMonitor
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-18 15:04:04 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-18 15:04:27 -0400
commitb9870f2e9293491a2f17b1c3bbd4e1bc2d505704 (patch)
treeb5d383d89e9be71c5a8925973b2cb45897b437a9 /src/lib/Bcfg2/Server/FileMonitor
parentb3dde5da6971834bcacba66fa6ece5c7879c4dd9 (diff)
downloadbcfg2-b9870f2e9293491a2f17b1c3bbd4e1bc2d505704.tar.gz
bcfg2-b9870f2e9293491a2f17b1c3bbd4e1bc2d505704.tar.bz2
bcfg2-b9870f2e9293491a2f17b1c3bbd4e1bc2d505704.zip
fixed gamin issues with late daemonization
Diffstat (limited to 'src/lib/Bcfg2/Server/FileMonitor')
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Gamin.py24
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Inotify.py4
2 files changed, 22 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
index 60f80c9c3..8a72fc0eb 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
@@ -9,6 +9,7 @@ from Bcfg2.Server.FileMonitor import Event, FileMonitor
logger = logging.getLogger(__name__)
+
class GaminEvent(Event):
"""
This class provides an event analogous to
@@ -23,13 +24,22 @@ class GaminEvent(Event):
if code in self.action_map:
self.action = self.action_map[code]
+
class Gamin(FileMonitor):
__priority__ = 10
def __init__(self, ignore=None, debug=False):
FileMonitor.__init__(self, ignore=ignore, debug=debug)
- self.mon = WatchMonitor()
+ self.mon = None
self.counter = 0
+ self.add_q = []
+
+ def start(self):
+ FileMonitor.start(self)
+ self.mon = WatchMonitor()
+ for monitor in self.add_q:
+ self.AddMonitor(*monitor)
+ self.add_q = []
def fileno(self):
return self.mon.get_fd()
@@ -38,10 +48,16 @@ class Gamin(FileMonitor):
"""queue up the event for later handling"""
self.events.append(GaminEvent(request_id, path, action))
- def AddMonitor(self, path, obj):
+ def AddMonitor(self, path, obj, handle=None):
"""Add a monitor to path, installing a callback to obj."""
- handle = self.counter
- self.counter += 1
+ if handle is None:
+ handle = self.counter
+ self.counter += 1
+
+ if not self.started:
+ self.add_q.append((path, obj, handle))
+ return handle
+
mode = os.stat(path)[stat.ST_MODE]
# Flush queued gamin events
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
index 60e26587e..6a8fd0201 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
@@ -3,7 +3,6 @@
import os
import sys
import logging
-import operator
import pyinotify
from Bcfg2.Compat import reduce
from Bcfg2.Server.FileMonitor import Event
@@ -11,6 +10,7 @@ from Bcfg2.Server.FileMonitor.Pseudo import Pseudo
logger = logging.getLogger(__name__)
+
class Inotify(Pseudo, pyinotify.ProcessEvent):
__priority__ = 1
action_map = {pyinotify.IN_CREATE: 'created',
@@ -22,6 +22,7 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
def __init__(self, ignore=None, debug=False):
Pseudo.__init__(self, ignore=ignore, debug=debug)
+ pyinotify.ProcessEvent(self)
self.event_filter = dict()
self.watches_by_path = dict()
# these are created in start() after the server is done forking
@@ -53,7 +54,6 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
try:
watch = self.wm.watches[ievent.wd]
except KeyError:
- err = sys.exc_info()[1]
logger.error("Error handling event for %s: Watch %s not found" %
(ievent.pathname, ievent.wd))
return