From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 485B8138334 for ; Wed, 20 Feb 2019 00:58:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 58A9AE0897; Wed, 20 Feb 2019 00:58:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 33208E0897 for ; Wed, 20 Feb 2019 00:58:10 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0DD44335CF7 for ; Wed, 20 Feb 2019 00:58:09 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AB19F545 for ; Wed, 20 Feb 2019 00:58:07 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1550623089.02922cb3a7eb72e9bf4cec9e30b35aa4adaa51c8.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/locks.py X-VCS-Directories: lib/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 02922cb3a7eb72e9bf4cec9e30b35aa4adaa51c8 X-VCS-Branch: master Date: Wed, 20 Feb 2019 00:58:07 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 56fb32bd-90f4-4308-a982-d65c0972fdd8 X-Archives-Hash: e74a67e7e1f226645c4113586e9b02bd commit: 02922cb3a7eb72e9bf4cec9e30b35aa4adaa51c8 Author: Zac Medico sony com> AuthorDate: Tue Feb 19 23:59:35 2019 +0000 Commit: Zac Medico gentoo org> CommitDate: Wed Feb 20 00:38:09 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=02922cb3 lockfile: use loop instead of recursion Copyright: Sony Interactive Entertainment Inc. Signed-off-by: Zac Medico gentoo.org> lib/portage/locks.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/portage/locks.py b/lib/portage/locks.py index a23d5cb56..fff27e55e 100644 --- a/lib/portage/locks.py +++ b/lib/portage/locks.py @@ -107,7 +107,34 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, If wantnewlockfile is True then this creates a lockfile in the parent directory as the file: '.' + basename + '.portage_lockfile'. """ + lock = None + while lock is None: + lock = _lockfile_iteration(mypath, wantnewlockfile=wantnewlockfile, + unlinkfile=unlinkfile, waiting_msg=waiting_msg, flags=flags) + if lock is None: + writemsg(_("lockfile removed by previous lock holder, retrying\n"), 1) + return lock + +def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False, + waiting_msg=None, flags=0): + """ + Acquire a lock on mypath, without retry. Return None if the lockfile + was removed by previous lock holder (caller must retry). + + @param mypath: lock file path + @type mypath: str + @param wantnewlockfile: use a separate new lock file + @type wantnewlockfile: bool + @param unlinkfile: remove lock file prior to unlock + @type unlinkfile: bool + @param waiting_msg: message to show before blocking + @type waiting_msg: str + @param flags: lock flags (only supports os.O_NONBLOCK) + @type flags: int + @rtype: bool + @return: unlockfile tuple on success, None if retry is needed + """ if not mypath: raise InvalidData(_("Empty path given")) @@ -274,12 +301,9 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, if isinstance(lockfilename, basestring) and \ myfd != HARDLINK_FD and unlinkfile and _lockfile_was_removed(myfd, lockfilename): - # The file was deleted on us... Keep trying to make one... + # Removed by previous lock holder... Caller will retry... os.close(myfd) - writemsg(_("lockfile recurse\n"), 1) - lockfilename, myfd, unlinkfile, locking_method = lockfile( - mypath, wantnewlockfile=wantnewlockfile, unlinkfile=unlinkfile, - waiting_msg=waiting_msg, flags=flags) + return None if myfd != HARDLINK_FD: