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

[minion-cvs] First work on threadsafety



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

Modified Files:
	Common.py Crypto.py 
Log Message:
First work on threadsafety

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- Common.py	7 Jan 2003 04:13:08 -0000	1.48
+++ Common.py	8 Jan 2003 08:04:25 -0000	1.49
@@ -23,6 +23,7 @@
 import stat
 import statvfs
 import sys
+import threading
 import time
 import traceback
 
@@ -115,7 +116,7 @@
 
     checkPrivateDir(d)
 
-_WARNED_DIRECTORIES = {}
+_WARNED_DIRECTORIES = {} # ???? Threading danger?
 
 def checkPrivateDir(d, recurse=1):
     """Return true iff d is a directory owned by this uid, set to mode
@@ -165,6 +166,7 @@
                 LOG.warn("Iffy mode %o on directory %s (Writable by gid %s)",
                          mode, d, st[stat.ST_GID])
             _WARNED_DIRECTORIES[d] = 1
+
 #----------------------------------------------------------------------
 # Secure filesystem operations.
 
@@ -369,6 +371,7 @@
            minSeverity, and sends its output to stderr."""
         self.configure(None)
         self.setMinSeverity(minSeverity)
+        self.__lock = threading.Lock()
 
     def configure(self, config):
         """Set up this Log object based on a ServerConfig or ClientConfig
@@ -452,8 +455,12 @@
         if _SEVERITIES.get(severity, 100) < self.severity:
             return
 
-        for h in self.handlers:
-            h.write(severity, m)
+        self.__lock.acquire()
+        try:
+            for h in self.handlers:
+                h.write(severity, m)
+        finally:
+            self.__lock.release()
 
     def trace(self, message, *args):
         "Write a trace (hyperverbose) message to the log"

Index: Crypto.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Crypto.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- Crypto.py	5 Jan 2003 13:19:53 -0000	1.35
+++ Crypto.py	8 Jan 2003 08:04:27 -0000	1.36
@@ -8,11 +8,12 @@
    the functions in mixminion.Crypto, and not call _minionlib's crypto
    functionality themselves."""
 
+import binascii
 import copy_reg
 import os
 import stat
 import sys
-import binascii
+import threading
 from types import StringType
 
 import mixminion._minionlib as _ml
@@ -588,13 +589,13 @@
             raise MixFatalError("Exhausted period of PRNG.")
         return prng(self.key,n,c)
 
-_theSharedPRNG = None
 def getCommonPRNG():
     '''Returns a general-use AESCounterPRNG, initializing it if necessary.'''
-    global _theSharedPRNG
-    if _theSharedPRNG is None:
-        _theSharedPRNG = AESCounterPRNG()
-    return _theSharedPRNG
+    # We create one PRNG per thread.
+    thisThread = threading.currentThread()
+    if not hasattr(thisThread, "minion_shared_PRNG"):
+        thisThread.minion_shared_PRNG = AESCounterPRNG()
+    return thisThread.minion_shared_PRNG
 
 #----------------------------------------------------------------------
 # TRNG implementation