summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2014-10-02 17:15:00 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2014-10-02 17:15:02 +0100
commit47daef1e47ea4ba3556f17bcb4ed5b08897fd876 (patch)
treef36434cbd771d9e2646682fd0da26600d664d657
parent294ad9fae1e7657829bb18066e2978360f5dd53b (diff)
downloaddeluge-47daef1e47ea4ba3556f17bcb4ed5b08897fd876.tar.gz
deluge-47daef1e47ea4ba3556f17bcb4ed5b08897fd876.tar.bz2
deluge-47daef1e47ea4ba3556f17bcb4ed5b08897fd876.zip
[#2335] [GTKUI] Fix startup failing with 'cannot acquire lock'
This issue was caused by an unclean shutdown of Deluge, usually on system shutdown, and upon rebooting the PID stored in the lockfile is in used by another process thus the lockfile is never removed. It affects users with Deluge set in startup applications as the PIDs are more likely to be reused. * Lockfile is removed if Deluge is restarted in IPC. * Renamed the old_tempfile variable to make it clearer as to it's role.
-rw-r--r--deluge/ui/gtkui/ipcinterface.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py
index 222001c09..9b79bb990 100644
--- a/deluge/ui/gtkui/ipcinterface.py
+++ b/deluge/ui/gtkui/ipcinterface.py
@@ -120,24 +120,28 @@ class IPCInterface(component.Component):
sys.exit(0)
else:
# Find and remove any restart tempfiles
- old_tempfile = glob(os.path.join(ipc_dir, 'tmp*deluge'))
- for f in old_tempfile:
+ restart_tempfile = glob(os.path.join(ipc_dir, 'tmp*deluge'))
+ for f in restart_tempfile:
os.remove(f)
lockfile = socket + ".lock"
log.debug("Checking if lockfile exists: %s", lockfile)
- if os.path.lexists(lockfile) or os.path.lexists(socket):
- try:
- os.kill(int(os.readlink(lockfile)), 0)
- except OSError:
+ if os.path.lexists(lockfile):
+ def delete_lockfile():
log.debug("Removing lockfile since it's stale.")
try:
os.remove(lockfile)
- except OSError, ex:
- log.error("Failed to delete IPC lockfile file: %s", ex)
- try:
os.remove(socket)
- except OSError, ex:
- log.error("Failed to delete IPC socket file: %s", ex)
+ except OSError as ex:
+ log.error("Failed to delete lockfile: %s", ex)
+
+ try:
+ os.kill(int(os.readlink(lockfile)), 0)
+ except OSError:
+ delete_lockfile()
+ else:
+ if restart_tempfile:
+ log.warning("Found running PID but it is not a Deluge process, removing lockfile...")
+ delete_lockfile()
try:
self.factory = Factory()
self.factory.protocol = IPCProtocolServer
@@ -154,7 +158,7 @@ class IPCInterface(component.Component):
gtk.gdk.notify_startup_complete()
sys.exit(0)
else:
- if old_tempfile:
+ if restart_tempfile:
log.error("Deluge restart failed: %s", e)
sys.exit(1)
else: