From bdba9cd00a6d4764f396998f71634fe67578bd4c Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 13 Nov 2009 01:07:36 +0000 Subject: [PATCH] Fix #1071 issue where Deluge will fail to start if there is a stale ipc lockfile --- deluge/ui/gtkui/ipcinterface.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 2ee48fd21..046073399 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -35,7 +35,7 @@ import sys -import os.path +import os import base64 import deluge.rencode @@ -104,6 +104,20 @@ class IPCInterface(component.Component): reactor.run() sys.exit(0) else: + lockfile = socket + ".lock" + log.debug("Checking if lockfile exists: %s", lockfile) + if os.path.lexists(lockfile): + try: + os.kill(int(os.readlink(lockfile)), 0) + except OSError: + log.debug("Removing lockfile since it's stale.") + try: + os.remove(lockfile) + os.remove(socket) + except Exception, e: + log.error("Problem deleting lockfile or socket file!") + log.exception(e) + try: self.factory = Factory() self.factory.protocol = IPCProtocolServer