- Added better handling of exception

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@179 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.5
Cyril Jaquier 20 years ago
parent b3a90d7492
commit dd27cafee3

@ -51,17 +51,25 @@ class PIDLock:
def create(self): def create(self):
""" Create PID lock. """ Create PID lock.
""" """
fileHandler = open(self.path, mode='w') try:
pid = os.getpid() fileHandler = open(self.path, mode='w')
fileHandler.write(`pid` + '\n') pid = os.getpid()
fileHandler.close() fileHandler.write(`pid` + '\n')
logSys.debug("Created PID lock (" + `pid` + ") in " + self.path) fileHandler.close()
logSys.debug("Created PID lock (" + `pid` + ") in " + self.path)
return True
except:
logSys.error("Unable to create PID lock " + self.path)
return False
def remove(self): def remove(self):
""" Remove PID lock. """ Remove PID lock.
""" """
os.remove(self.path) try:
logSys.debug("Removed PID lock " + self.path) os.remove(self.path)
logSys.debug("Removed PID lock " + self.path)
except OSError:
logSys.error("Unable to remove PID lock " + self.path)
def exists(self): def exists(self):
""" Returns the current PID if Fail2Ban is running or False """ Returns the current PID if Fail2Ban is running or False

Loading…
Cancel
Save