From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions
Date: Sat, 21 Dec 2013 04:49:37 -0500 [thread overview]
Message-ID: <1387619377-19614-1-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <20131220210717.143e9f02@caribou.gateway.pace.com>
The $BASHPID variable is new to bash-4.0, so we need to add fallback logic
to support older versions (notably, bash-3.2).
Reported-by: Ryan Hill <dirtyepic@gentoo.org>
---
bin/ebuild-helpers/prepstrip | 4 ++--
bin/ebuild.sh | 2 +-
bin/helper-functions.sh | 2 +-
bin/isolated-functions.sh | 9 ++++++++-
bin/phase-functions.sh | 2 +-
bin/phase-helpers.sh | 2 +-
6 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip
index 9b2d47c..64ea80d 100755
--- a/bin/ebuild-helpers/prepstrip
+++ b/bin/ebuild-helpers/prepstrip
@@ -116,7 +116,7 @@ save_elf_sources() {
buildid=$(debugedit -i \
-b "${WORKDIR}" \
-d "${prepstrip_sources_dir}" \
- -l "${tmpdir}/sources/${x##*/}.${BASHPID}" \
+ -l "${tmpdir}/sources/${x##*/}.${BASHPID:-$(__bashpid)}" \
"${x}")
}
@@ -208,7 +208,7 @@ process_elf() {
# see if we can split & strip at the same time
if [[ -n ${SPLIT_STRIP_FLAGS} ]] ; then
local shortname="${x##*/}.debug"
- local splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID}"
+ local splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID:-$(__bashpid)}"
${already_stripped} || \
${STRIP} ${strip_flags} \
-f "${splitdebug}" \
diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 35f4b91..be044e0 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -468,7 +468,7 @@ if [[ -n ${QA_INTERCEPTORS} ]] ; then
fi
# Subshell/helper die support (must export for the die helper).
-export EBUILD_MASTER_PID=$BASHPID
+export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)}
trap 'exit 1' SIGTERM
if ! has "$EBUILD_PHASE" clean cleanrm depend && \
diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh
index 4a46278..b9bc74a 100644
--- a/bin/helper-functions.sh
+++ b/bin/helper-functions.sh
@@ -34,7 +34,7 @@ __multijob_init() {
}
__multijob_child_init() {
- trap 'echo ${BASHPID} $? >&'${mj_write_fd} EXIT
+ trap 'echo ${BASHPID:-$(__bashpid)} $? >&'${mj_write_fd} EXIT
trap 'exit 1' INT TERM
}
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 42d9e70..b99aec7 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -98,6 +98,13 @@ nonfatal() {
PORTAGE_NONFATAL=1 "$@"
}
+__bashpid() {
+ # The BASHPID variable is new to bash-4.0, so add a hack for older
+ # versions. This must be used like so:
+ # ${BASHPID:-$(__bashpid)}
+ sh -c 'echo ${PPID}'
+}
+
__helpers_die() {
if ___eapi_helpers_can_die; then
die "$@"
@@ -216,7 +223,7 @@ die() {
[[ -n $PORTAGE_IPC_DAEMON ]] && "$PORTAGE_BIN_PATH"/ebuild-ipc exit 1
# subshell die support
- [[ $BASHPID = $EBUILD_MASTER_PID ]] || kill -s SIGTERM $EBUILD_MASTER_PID
+ [[ ${BASHPID:-$(__bashpid)} == ${EBUILD_MASTER_PID} ]] || kill -s SIGTERM ${EBUILD_MASTER_PID}
exit 1
}
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index 711b721..f39a024 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -830,7 +830,7 @@ __ebuild_main() {
# setup EBUILD_MASTER_PID to refer to the current $BASHPID,
# which seems to give the best results when further
# nested subshells call die.
- export EBUILD_MASTER_PID=$BASHPID
+ export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)}
trap 'exit 1' SIGTERM
#a reasonable default for $S
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 1a7ae03..412decb 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -469,7 +469,7 @@ unpack() {
econf() {
local x
- local pid=${BASHPID}
+ local pid=${BASHPID:-$(__bashpid)}
if ! ___eapi_has_prefix_variables; then
local EPREFIX=
--
1.8.4.3
prev parent reply other threads:[~2013-12-21 9:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-17 23:23 [gentoo-portage-dev] [PATCH] econf: update config.{sub,guess} atomically to avoid races Mike Frysinger
2013-12-17 23:28 ` [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} " Mike Frysinger
2013-12-18 0:26 ` Brian Dolbec
2013-12-18 1:08 ` Alec Warner
2013-12-18 1:41 ` Greg Turner
2013-12-18 1:58 ` Alec Warner
2013-12-18 2:53 ` Greg Turner
2013-12-18 5:16 ` Alec Warner
2013-12-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
2013-12-21 9:23 ` Mike Frysinger
2013-12-21 9:49 ` Mike Frysinger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1387619377-19614-1-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox