Skip to content

Commit

Permalink
Ignore malformed and stale cache locks [BZ#1091404]
Browse files Browse the repository at this point in the history
  • Loading branch information
psss committed May 17, 2014
1 parent 418935d commit 2874c9c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion source/cache.py
Expand Up @@ -337,8 +337,19 @@ def enter(self, filename=None):
# Check for existing cache lock, set mode appropriately
try:
lock = open(self._lock)
log.warn("Found lock {0}, opening read-only".format(self._lock))
pid = lock.readline().strip()
lock.close()
# Make sure the lock PID is sane (otherwise ignore it)
try:
pid = int(pid)
except ValueError:
log.warn("Malformed cache lock ({0}), ignoring".format(pid))
raise IOError
# Check that the process is still running
if not os.path.exists("/proc/{0}".format(pid)):
log.cache("Breaking stale lock (process {0} dead)".format(pid))
raise IOError
log.info("Found lock {0}, opening read-only".format(self._lock))
self._mode = "read-only"
except IOError:
log.cache("Creating cache lock {0}".format(self._lock))
Expand Down

0 comments on commit 2874c9c

Please sign in to comment.