diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-08-29 00:56:46 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-08-29 00:56:46 +0000 |
commit | 803b7e8868dfa6bd72520127c61377b17519068e (patch) | |
tree | dc7e8f74c227bf1bcb9e4ecd1660ee9a92717f2a /sys-devel/binutils-config | |
parent | New package for bug 377565 (diff) | |
download | gentoo-2-803b7e8868dfa6bd72520127c61377b17519068e.tar.gz gentoo-2-803b7e8868dfa6bd72520127c61377b17519068e.tar.bz2 gentoo-2-803b7e8868dfa6bd72520127c61377b17519068e.zip |
Make profile switching more atomic #380759.
(Portage version: 2.2.0_alpha51/cvs/Linux x86_64)
Diffstat (limited to 'sys-devel/binutils-config')
-rw-r--r-- | sys-devel/binutils-config/ChangeLog | 5 | ||||
-rwxr-xr-x | sys-devel/binutils-config/files/binutils-config-3 | 46 |
2 files changed, 37 insertions, 14 deletions
diff --git a/sys-devel/binutils-config/ChangeLog b/sys-devel/binutils-config/ChangeLog index 58e5d0b03297..6e07f87515e6 100644 --- a/sys-devel/binutils-config/ChangeLog +++ b/sys-devel/binutils-config/ChangeLog @@ -1,6 +1,9 @@ # ChangeLog for sys-devel/binutils-config # Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/ChangeLog,v 1.48 2011/08/23 16:09:21 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/ChangeLog,v 1.49 2011/08/29 00:56:45 vapier Exp $ + + 29 Aug 2011; Mike Frysinger <vapier@gentoo.org> files/binutils-config-3: + Make profile switching more atomic #380759. 23 Aug 2011; Mike Frysinger <vapier@gentoo.org> files/binutils-config-3: Make sure all the profile specs still work after previous rework. diff --git a/sys-devel/binutils-config/files/binutils-config-3 b/sys-devel/binutils-config/files/binutils-config-3 index 734b2d54e14e..725ae43aa6f3 100755 --- a/sys-devel/binutils-config/files/binutils-config-3 +++ b/sys-devel/binutils-config/files/binutils-config-3 @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.4 2011/08/23 16:09:21 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.5 2011/08/29 00:56:46 vapier Exp $ # Format of /etc/env.d/binutils/: # config-TARGET: CURRENT=version for TARGET @@ -59,6 +59,26 @@ mv_if_diff() { mv -f "$1" "$2" fi } +atomic_ln() { + local target=$1 linkdir=$2 linkname=$3 linktmp linkfull + linktmp="${linkdir}/.binutils-config.tmp.${linkname}" + linkfull="${linkdir}/${linkname}" + if [[ -d ${linkfull} ]] ; then + # if linking to a dir, we need a little magic to + # make it atomic since `mv -T` is not portable + rm -rf "${linktmp}" + mkdir -p "${linktmp}" + ln -sf "${target}" "${linktmp}/${linkname}" + mv "${linktmp}/${linkname}" "${linktmp}/../" + rmdir "${linktmp}" + else + # `ln` will expand into unlink();symlink(); which + # is not atomic for a small amount of time, but + # `mv` is a single rename() call + ln -sf "${target}" "${linktmp}" + mv "${linktmp}" "${linkfull}" + fi +} setup_env() { unset TARGET VER LIBPATH FAKE_TARGETS @@ -122,14 +142,14 @@ switch_profile() { cd "${ROOT}/${BINPATH}" || exit 1 mkdir -p "${ROOT}/${BINPATH_LINKS}" "${ROOT}/usr/bin" for x in * ; do - ln -sf "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}/${x}" - ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${TARGET}-${x} + atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}" + atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin/" "${TARGET}-${x}" for fake in ${FAKE_TARGETS} ; do [[ -f ${ENV_D}/config-${fake} ]] && continue - ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${fake}-${x} + atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin" "${fake}-${x}" done if [[ ${TARGET} == ${HOST} ]] ; then - ln -sf ${TARGET}-${x} "${ROOT}"/usr/bin/${x} + atomic_ln "${TARGET}-${x}" "${ROOT}/usr/bin" "${x}" fi done @@ -147,12 +167,12 @@ switch_profile() { rmdir "${ROOT}"/usr/${TARGET}/lib >& /dev/null fi # When upgrading, we need to clean up ldscripts and libs - rm -rf "${dstlib}/ldscripts" "${ROOT}/${BINPATH_LINKS}"/ldscripts mkdir -p "${dstlib}" - ln -sf "${LIBPATH}/ldscripts" "${dstlib}"/ldscripts - find -L "${dstlib}" -type l -exec rm {} + + rm -rf "${ROOT}/${BINPATH_LINKS}"/ldscripts + atomic_ln "${LIBPATH}/ldscripts" "${dstlib}" "ldscripts" + find -L "${dstlib}" -type l -exec rm -v {} + for x in lib* ; do - ln -sf "${LIBPATH}/${x}" "${dstlib}/${x}" + atomic_ln "${LIBPATH}/${x}" "${dstlib}" "${x}" done # @@ -164,7 +184,7 @@ switch_profile() { if [[ ${HOST} == ${TARGET} ]] ; then mkdir -p "${ROOT}/usr/include" for x in * ; do - ln -sf "${INCPATH}/${x}" "${ROOT}/usr/include/${x}" + atomic_ln "${INCPATH}/${x}" "${ROOT}/usr/include" "${x}" done else # Clean out old path -- cannot use '-exec {} +' syntax here @@ -337,14 +357,14 @@ switch_linker() { setup_env || return 1 # does this binutils even support the requested linker ? - if [[ ! -e ${BINPATH}/ld.${ld} ]] ; then + if [[ ! -e ${ROOT}/${BINPATH}/ld.${ld} ]] ; then eerror "${argv0}: sorry, but ${PROFILE} doesn't support the ${ld} linker" exit 1 fi # switch it up ebegin "Setting default linker to ${ld} for ${PROFILE}" - ln -sf ld.${ld} "${BINPATH}"/ld + atomic_ln ld.${ld} "${ROOT}/${BINPATH}" ld eend $? } switch_linker_gold() { switch_linker gold ; } @@ -389,7 +409,7 @@ while [[ $# -gt 0 ]] ; do -h|--help) usage 0 ;; -V|--version) unset Header - cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.4 2011/08/23 16:09:21 vapier Exp $" + cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.5 2011/08/29 00:56:46 vapier Exp $" cvsver=${cvsver##*binutils-config-} bver=${cvsver%%,v *} cvsver=${cvsver#* } |