- Timestamp:
- 08/11/06 00:12:08 (18 years ago)
- Location:
- tea4cups/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/NEWS
r684 r688 23 23 Tea4CUPS News : 24 24 25 * 3.12 (2006-08-1 0) :25 * 3.12 (2006-08-11) : 26 26 27 - Serializes accesses to the same device from different queues 28 or print servers through file locking facilities (works over 29 NFS). 30 27 31 - Improved support for CUPS 1.2.x and higher. 28 32 -
tea4cups/trunk/tea4cups
r687 r688 83 83 import signal 84 84 import socket 85 import fcntl 85 86 import urllib2 86 87 from struct import pack, unpack 87 88 88 __version__ = "3.12 alpha2_unofficial"89 __version__ = "3.12_unofficial" 89 90 90 91 class TeeError(Exception): … … 909 910 self.config = None 910 911 self.conffile = None 911 912 self.LockFile = None 913 914 def waitForLock(self) : 915 """Waits until we can acquire the lock file.""" 916 self.logDebug("Waiting for lock...") 917 lockfilename = self.DeviceURI.replace("/", ".") 918 lockfilename = lockfilename.replace(":", ".") 919 lockfilename = lockfilename.replace("?", ".") 920 lockfilename = lockfilename.replace("&", ".") 921 lockfilename = lockfilename.replace("@", ".") 922 lockfilename = os.path.join(self.Directory, "%s-%s..LCK" % (self.myname, lockfilename)) 923 stillrunning = True 924 while 1 : 925 self.LockFile = open(lockfilename, "a+") 926 fcntl.lockf(self.LockFile, fcntl.LOCK_EX) # Will wait until lock available 927 self.LockFile.seek(0, 0) 928 try : 929 oldpid = int(self.LockFile.readlines()[-1].strip()) 930 except : 931 stillrunning = False 932 else : 933 try : 934 os.kill(oldpid, 0) 935 except OSError : 936 stillrunning = False 937 if not stillrunning : 938 self.LockFile.truncate(0) 939 self.LockFile.seek(0, 0) 940 self.LockFile.write("%s\n" % self.pid) 941 self.LockFile.flush() 942 break 943 else : 944 time.sleep(0.1) 945 self.logDebug("Lock acquired.") 946 912 947 def readConfig(self) : 913 948 """Reads the configuration file.""" … … 1118 1153 jbing = jbing[-1] 1119 1154 (dummy, self.JobBilling) = jbing 1120 1121 1155 1122 1156 def parseIPPRequestFile(self) : 1123 1157 """Parses the IPP message file and returns a tuple (filename, parsedvalue).""" … … 1227 1261 def cleanUp(self) : 1228 1262 """Cleans up the place.""" 1263 self.logDebug("Cleaning up...") 1229 1264 if (not isTrue(self.getPrintQueueOption(self.PrinterName, "keepfiles", ignore=1))) \ 1230 1265 and os.path.exists(self.DataFile) : … … 1233 1268 except OSError, msg : 1234 1269 self.logInfo("Problem when removing %s : %s" % (self.DataFile, msg), "error") 1270 self.logDebug("Removing lock...") 1271 try : 1272 fcntl.flock(self.LockFile, fcntl.LOCK_UN) 1273 self.LockFile.close() 1274 # NB : we don't remove the lock file, since it might already be opened by another process. 1275 except : 1276 self.logInfo("Problem while removing lock.", "error") 1277 else : 1278 self.logDebug("Lock removed.") 1279 self.logDebug("Clean.") 1235 1280 1236 1281 def runBranches(self) : … … 1430 1475 wrapper.readConfig() 1431 1476 wrapper.initBackend() 1477 wrapper.waitForLock() 1432 1478 wrapper.saveDatasAndCheckSum() 1433 1479 wrapper.exportAttributes()