Commit 4fcacbf9 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(try_symlink): Break stale lock files.

parent 1c4ce900
......@@ -113,11 +113,34 @@ def try_symlink(hostname, pid):
except os.error, e:
if e.errno != errno.EEXIST:
raise
locker = None
try:
return os.readlink(LOCKNAME)
locker = os.readlink(LOCKNAME)
except os.error, e:
if e.errno != errno.ENOENT:
raise
if locker != None:
if locker[:len(hostname)] != hostname:
# Locked by a foreign host.
return locker
oldpid = locker[len(hostname):]
if len(oldpid) < 2 or oldpid[0] != ":":
# Broken lock file. Return it anyhow.
return locker
try:
os.kill(string.atoi(oldpid[1:]), 0)
# Lock owner still living.
return locker
except os.error, e:
if e.errno == errno.EPERM:
# Lock owner still living.
return locker
elif e.errno == errno.ESRCH:
os.unlink(LOCKNAME)
else:
raise
time.sleep(1) # Just in case...
def myhostname():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment