summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-15 17:47:53 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-15 17:47:53 +0000
commit009273bc78d9ab9d1e01c35f1056b17d52d7b58a (patch)
treee4572dc4e79b77198df500411822e1c194c5cc12 /pym/portage_locks.py
parentsilence extdebug errors when on bash2; it's handled by the code already, just... (diff)
downloadportage-multirepo-009273bc78d9ab9d1e01c35f1056b17d52d7b58a.tar.gz
portage-multirepo-009273bc78d9ab9d1e01c35f1056b17d52d7b58a.tar.bz2
portage-multirepo-009273bc78d9ab9d1e01c35f1056b17d52d7b58a.zip
fix a race and prevent unlinking of a file locked by another process in portage_locks.unlockfile()
svn path=/main/trunk/; revision=2714
Diffstat (limited to 'pym/portage_locks.py')
-rw-r--r--pym/portage_locks.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/pym/portage_locks.py b/pym/portage_locks.py
index a6e1afe5..7a9b5567 100644
--- a/pym/portage_locks.py
+++ b/pym/portage_locks.py
@@ -147,10 +147,9 @@ def unlockfile(mytuple):
unhardlink_lockfile(lockfilename)
return True
- if type(lockfilename) == types.StringType and not os.path.exists(lockfilename):
+ if type(lockfilename) == types.StringType and os.fstat(myfd).st_nlink != 1:
portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
- if (myfd != None) and type(lockfilename) == types.StringType:
- os.close(myfd)
+ os.close(myfd)
return False
try:
@@ -178,9 +177,14 @@ def unlockfile(mytuple):
# We can safely delete the file.
portage_util.writemsg("Got the lockfile...\n",1)
#portage_util.writemsg("Unlinking...\n")
- os.unlink(lockfilename)
- portage_util.writemsg("Unlinked lockfile...\n",1)
- locking_method(myfd,fcntl.LOCK_UN)
+ if os.fstat(myfd).st_nlink == 1:
+ os.unlink(lockfilename)
+ portage_util.writemsg("Unlinked lockfile...\n",1)
+ locking_method(myfd,fcntl.LOCK_UN)
+ else:
+ portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
+ os.close(myfd)
+ return False
except SystemExit, e:
raise
except Exception, e: