[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Run in a reasonable daemon mode; fork less; lock a litt...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv27308/lib/mixminion

Modified Files:
	Common.py 
Log Message:
Run in a reasonable daemon mode; fork less; lock a little; be less verbose when we are not verbose.

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- Common.py	15 Dec 2002 04:15:37 -0000	1.33
+++ Common.py	15 Dec 2002 05:55:30 -0000	1.34
@@ -5,12 +5,12 @@
 
    Common functionality and utility code for Mixminion"""
 
-__all__ = [ 'LOG', 'MixError', 'MixFatalError', 'MixProtocolError', 'ceilDiv',
-	    'checkPrivateDir', 'createPrivateDir', 'floorDiv', 'formatBase64',
-	    'formatDate', 'formatTime', 'installSignalHandlers',
-	    'isSMTPMailbox', 'mkgmtime', 'onReset', 'onTerminate',
-	    'previousMidnight', 'secureDelete', 'stringContains',
-	    'waitForChildren' ]
+__all__ = [ 'LOG', 'LogStream', 'MixError', 'MixFatalError',
+	    'MixProtocolError', 'ceilDiv', 'checkPrivateDir',
+	    'createPrivateDir', 'floorDiv', 'formatBase64', 'formatDate',
+	    'formatTime', 'installSignalHandlers', 'isSMTPMailbox', 'mkgmtime',
+	    'onReset', 'onTerminate', 'previousMidnight', 'secureDelete',
+	    'stringContains', 'waitForChildren' ]
 
 import base64
 import calendar
@@ -364,6 +364,7 @@
     def configure(self, config):
 	"""Set up this Log object based on a ServerConfig or ClientConfig
 	   object"""
+        # XXXX001 Don't EchoLogMessages when NoDaemon==0.
         self.handlers = []
         if config == None or not config.has_section("Server"):
             self.setMinSeverity("WARN")
@@ -493,6 +494,21 @@
 
 # The global 'Log' instance for the mixminion client or server.
 LOG = Log('WARN')
+
+class LogStream:
+    """Replacement for stdout or stderr when running in daemon mode;
+       sends all output to log.
+       
+       We don't actually want to use these; but they keep us from dropping
+       prints on the floor.
+       """
+    def __init__(self, name, severity):
+	self.name = name
+	self.severity = severity
+    def write(self, s):
+	LOG.log(self.severity, "->%s: %s", self.name, s)
+    def flush(self): pass
+    def close(self): pass
 
 #----------------------------------------------------------------------
 # Time processing