Gentoo Archives: gentoo-commits

From: Mike Gilbert <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: bin/
Date: Fri, 04 Feb 2022 17:32:27
Message-Id: 1643825489.d610d14325fbe65f9a011d643be74c95098c3241.floppym@gentoo
1 commit: d610d14325fbe65f9a011d643be74c95098c3241
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 2 18:07:19 2022 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 2 18:11:29 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=d610d143
7
8 estrip: fix race when creating build-id debug symlinks
9
10 Bug: https://bugs.gentoo.org/831927
11 Closes: https://github.com/gentoo/portage/pull/786
12 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
13
14 bin/estrip | 19 ++++++++++++++++---
15 1 file changed, 16 insertions(+), 3 deletions(-)
16
17 diff --git a/bin/estrip b/bin/estrip
18 index 599ca2ceb..cdad58c31 100755
19 --- a/bin/estrip
20 +++ b/bin/estrip
21 @@ -189,6 +189,19 @@ save_elf_sources() {
22 "${x}")
23 }
24
25 +# Try to create a symlink.
26 +# Return success if it already exists.
27 +__try_symlink() {
28 + local target=$1
29 + local name=$2
30 + # Check for an existing link before and after in case we are racing against
31 + # another process.
32 + [[ -L ${name} ]] ||
33 + ln -s "${target}" "${name}" ||
34 + [[ -L ${name} ]] ||
35 + die "failed to create symlink '${name}'"
36 +}
37 +
38 # Usage: save_elf_debug <src> <inode_debug> [splitdebug]
39 save_elf_debug() {
40 ${FEATURES_splitdebug} || return 0
41 @@ -245,7 +258,7 @@ save_elf_debug() {
42 [[ -g ${src} || -u ${src} ]] && args+=",go-r"
43 chmod ${args} "${dst}"
44 # symlink so we can read the name back.
45 - ln -s "${dst}" "${inode_debug}" || die "failed to create symlink '${inode_debug}'"
46 + __try_symlink "${dst}" "${inode_debug}"
47
48 # if we don't already have build-id from debugedit, look it up
49 if [[ -z ${buildid} ]] ; then
50 @@ -258,8 +271,8 @@ save_elf_debug() {
51 local src_buildid_rel="../../../../../${src#${ED%/}/}"
52 local dst_buildid_rel="../../${dst#${ED%/}/usr/lib/debug/}"
53 mkdir -p "${buildid_dir}" || die
54 - [[ -L "${buildid_file}".debug ]] || ln -s "${dst_buildid_rel}" "${buildid_file}.debug" || die "failed to create symlink '${buildid_file}.debug'"
55 - [[ -L "${buildid_file}" ]] || ln -s "${src_buildid_rel}" "${buildid_file}" || die "failed to create symlink '${buildid_file}'"
56 + __try_symlink "${dst_buildid_rel}" "${buildid_file}.debug"
57 + __try_symlink "${src_buildid_rel}" "${buildid_file}"
58 fi
59 fi
60 fi