* [gentoo-portage-dev] [PATCH] estrip: fix race when creating build-id debug symlinks
@ 2022-02-02 18:12 Mike Gilbert
0 siblings, 0 replies; only message in thread
From: Mike Gilbert @ 2022-02-02 18:12 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Mike Gilbert
Bug: https://bugs.gentoo.org/831927
Closes: https://github.com/gentoo/portage/pull/786
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
---
bin/estrip | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/bin/estrip b/bin/estrip
index 599ca2ceb..cdad58c31 100755
--- a/bin/estrip
+++ b/bin/estrip
@@ -189,6 +189,19 @@ save_elf_sources() {
"${x}")
}
+# Try to create a symlink.
+# Return success if it already exists.
+__try_symlink() {
+ local target=$1
+ local name=$2
+ # Check for an existing link before and after in case we are racing against
+ # another process.
+ [[ -L ${name} ]] ||
+ ln -s "${target}" "${name}" ||
+ [[ -L ${name} ]] ||
+ die "failed to create symlink '${name}'"
+}
+
# Usage: save_elf_debug <src> <inode_debug> [splitdebug]
save_elf_debug() {
${FEATURES_splitdebug} || return 0
@@ -245,7 +258,7 @@ save_elf_debug() {
[[ -g ${src} || -u ${src} ]] && args+=",go-r"
chmod ${args} "${dst}"
# symlink so we can read the name back.
- ln -s "${dst}" "${inode_debug}" || die "failed to create symlink '${inode_debug}'"
+ __try_symlink "${dst}" "${inode_debug}"
# if we don't already have build-id from debugedit, look it up
if [[ -z ${buildid} ]] ; then
@@ -258,8 +271,8 @@ save_elf_debug() {
local src_buildid_rel="../../../../../${src#${ED%/}/}"
local dst_buildid_rel="../../${dst#${ED%/}/usr/lib/debug/}"
mkdir -p "${buildid_dir}" || die
- [[ -L "${buildid_file}".debug ]] || ln -s "${dst_buildid_rel}" "${buildid_file}.debug" || die "failed to create symlink '${buildid_file}.debug'"
- [[ -L "${buildid_file}" ]] || ln -s "${src_buildid_rel}" "${buildid_file}" || die "failed to create symlink '${buildid_file}'"
+ __try_symlink "${dst_buildid_rel}" "${buildid_file}.debug"
+ __try_symlink "${src_buildid_rel}" "${buildid_file}"
fi
fi
fi
--
2.35.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-02 18:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-02 18:12 [gentoo-portage-dev] [PATCH] estrip: fix race when creating build-id debug symlinks Mike Gilbert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox