add a __bashpid helper for <bash-4.0 versions
authorMike Frysinger <vapier@gentoo.org>
Sat, 21 Dec 2013 09:46:10 +0000 (04:46 -0500)
committerMike Frysinger <vapier@gentoo.org>
Sat, 21 Dec 2013 09:46:10 +0000 (04:46 -0500)
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
bin/ebuild.sh
bin/helper-functions.sh
bin/isolated-functions.sh
bin/phase-functions.sh
bin/phase-helpers.sh

index 9b2d47cbd9dbdc1745aa8ce170132d3408c16e35..64ea80d713f6bd74d0e088b68c98c8ce45eefa41 100755 (executable)
@@ -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}" \
index 35f4b912a9fafacd6134926d8ffbebac8b53d56a..be044e08d0029df19436f8bd3c12453db0589d88 100755 (executable)
@@ -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 && \
index 4a46278004214cbc2e709ce7a13f2d6ae61d9267..b9bc74a2ebac7cc210c6a52aaa9fa6ee39edcf95 100644 (file)
@@ -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
 }
 
index 42d9e708d52c97432901a43d5c5caa7529287f39..b99aec729555e249d37d0d47a2fae9fb6f461036 100644 (file)
@@ -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
 }
 
index 711b7211634251ce167a8013a6ab6001f75e2fd2..f39a024a23ff60d7af351842fdcb2d9b1d2f69c2 100644 (file)
@@ -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
index 1a7ae03c5b4da4580027edb52397bd431f29a4fe..412decbe02bd58cee593cc777f5f48a34e33992c 100644 (file)
@@ -469,7 +469,7 @@ unpack() {
 
 econf() {
        local x
-       local pid=${BASHPID}
+       local pid=${BASHPID:-$(__bashpid)}
 
        if ! ___eapi_has_prefix_variables; then
                local EPREFIX=