From 3d9318ad3e1882a02b9345dcae1459934585b793 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Wed, 23 Feb 2005 17:31:46 +0000 Subject: [PATCH] - Splitted "checkForPID" into "createPID" and "checkForPID". Fixed the bug which created a PID lock file when calling Fail2Ban with the kill option git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@71 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fail2ban.py b/fail2ban.py index 7372bae5..b0aa10cd 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -175,13 +175,17 @@ def checkForPID(lockfile): pid = fileHandler.readline() return pid except IOError: - fileHandler = open(lockfile, mode='w') - pid = os.getpid() - fileHandler.write(`pid`+'\n') - fileHandler.close() - logSys.debug("Created PID lock ("+`pid`+") in "+lockfile) return False +def createPID(lockfile): + """ Creates a PID lock file with the current PID. + """ + fileHandler = open(lockfile, mode='w') + pid = os.getpid() + fileHandler.write(`pid`+'\n') + fileHandler.close() + logSys.debug("Created PID lock ("+`pid`+") in "+lockfile) + def removePID(lockfile): """ Remove PID lock. """ @@ -424,6 +428,8 @@ if __name__ == "__main__": if pid: logSys.error("Fail2Ban already running with PID "+pid) sys.exit(-1) + else: + createPID(conf["pidlock"]) logSys.debug("ConfFile is "+conf["conffile"]) logSys.debug("BanTime is "+`conf["bantime"]`)