econf: update configure/config.{sub,guess} atomically to avoid races
authorMike Frysinger <vapier@gentoo.org>
Tue, 17 Dec 2013 23:23:12 +0000 (18:23 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 17 Dec 2013 23:27:04 +0000 (18:27 -0500)
Use $BASHPID which will be unique even in subshells.

URL: https://bugs.gentoo.org/487478

bin/phase-helpers.sh

index ec48c94eca8045f581c6071542ed06b6375032ee..1a7ae03c5b4da4580027edb52397bd431f29a4fe 100644 (file)
@@ -469,6 +469,7 @@ unpack() {
 
 econf() {
        local x
+       local pid=${BASHPID}
 
        if ! ___eapi_has_prefix_variables; then
                local EPREFIX=
@@ -501,18 +502,22 @@ econf() {
                if [[ -n $CONFIG_SHELL && \
                        "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
                        # preserve timestamp, see bug #440304
-                       touch -r "$ECONF_SOURCE/configure" "$ECONF_SOURCE/configure._portage_tmp_.$$" || die
-                       sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
-                               die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
-                       touch -r "$ECONF_SOURCE/configure._portage_tmp_.$$" "$ECONF_SOURCE/configure" || die
-                       rm -f "$ECONF_SOURCE/configure._portage_tmp_.$$"
+                       touch -r "${ECONF_SOURCE}/configure" "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
+                       sed -i \
+                               -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
+                               "${ECONF_SOURCE}/configure" \
+                               || die "Substition of shebang in '${ECONF_SOURCE}/configure' failed"
+                       touch -r "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" "${ECONF_SOURCE}/configure" || die
+                       rm -f "${ECONF_SOURCE}/configure._portage_tmp_.${pid}"
                fi
                if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
                        find "${WORKDIR}" -type f '(' \
                        -name config.guess -o -name config.sub ')' -print0 | \
                        while read -r -d $'\0' x ; do
                                __vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
-                               cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
+                               # Make sure we do this atomically incase we're run in parallel. #487478
+                               cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.${pid}"
+                               mv -f "${x}.${pid}" "${x}"
                        done
                fi