commit: fe3e50025fee15d59c4956a39b675faf50555c46 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org> AuthorDate: Wed Nov 17 18:23:07 2021 +0000 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> CommitDate: Fri Nov 19 16:16:07 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fe3e5002
estrip: fix lockfile handling The previous code would wait for the first link to an inode to be processed, and would then allow multiple processes to process duplicate links to the same inode. This behavior leads to a race condition in save_elf_debug. The new code ensures that each inode is accessed by a single process at a time. Closes: https://bugs.gentoo.org/823798 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> bin/estrip | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/estrip b/bin/estrip index 0ad79e2a3..599ca2ceb 100755 --- a/bin/estrip +++ b/bin/estrip @@ -270,7 +270,9 @@ save_elf_debug() { process_elf() { local x=$1 inode_link=$2 strip_flags=${*:3} local ed_noslash=${ED%/} - local already_stripped lockfile xt_data + local already_stripped xt_data + local lockfile=${inode_link}_lockfile + local locktries=100 __vecho " ${x:${#ed_noslash}}" @@ -279,13 +281,10 @@ process_elf() { # So, use a lockfile to prevent interference (easily observed with # dev-vcs/git which creates ~111 hardlinks to one file in # /usr/libexec/git-core). - lockfile=${inode_link}_lockfile - if ! ln "${inode_link}" "${lockfile}" 2>/dev/null ; then - while [[ -f ${lockfile} ]] ; do - sleep 1 - done - unset lockfile - fi + while ! ln "${inode_link}" "${lockfile}" 2>/dev/null; do + (( --locktries > 0 )) || die "failed to acquire lock '${lockfile}'" + sleep 1 + done [ -f "${inode_link}_stripped" ] && already_stripped=true || already_stripped=false
