diff --git a/utils/pidlock.py b/utils/pidlock.py index 6eeb0dde..c5a4176a 100644 --- a/utils/pidlock.py +++ b/utils/pidlock.py @@ -51,17 +51,25 @@ class PIDLock: def create(self): """ Create PID lock. """ - fileHandler = open(self.path, mode='w') - pid = os.getpid() - fileHandler.write(`pid` + '\n') - fileHandler.close() - logSys.debug("Created PID lock (" + `pid` + ") in " + self.path) + try: + fileHandler = open(self.path, mode='w') + pid = os.getpid() + fileHandler.write(`pid` + '\n') + 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): """ Remove PID lock. """ - os.remove(self.path) - logSys.debug("Removed PID lock " + self.path) + try: + 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): """ Returns the current PID if Fail2Ban is running or False