Wed, 06 Feb 2013 11:36:19 +0000
8007625: race with nested repos in /common/bin/hgforest.sh
Reviewed-by: dholmes, ohair, ohrstrom
common/bin/hgforest.sh | file | annotate | diff | comparison | revisions | |
get_source.sh | file | annotate | diff | comparison | revisions |
1.1 --- a/common/bin/hgforest.sh Thu Jan 31 17:04:19 2013 -0800 1.2 +++ b/common/bin/hgforest.sh Wed Feb 06 11:36:19 2013 +0000 1.3 @@ -64,33 +64,33 @@ 1.4 mkdir -p ${tmp} 1.5 1.6 safe_interrupt () { 1.7 - if [ -d ${tmp} ]; then 1.8 - if [ "`ls ${tmp}`" != "" ]; then 1.9 - echo "Waiting for processes ( `cat ${tmp}/* | tr '\n' ' '`) to terminate nicely!" 1.10 + if [ -d ${tmp} ]; then 1.11 + if [ "`ls ${tmp}/*.pid`" != "" ]; then 1.12 + echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" 1.13 sleep 1 1.14 # Pipe stderr to dev/null to silence kill, that complains when trying to kill 1.15 # a subprocess that has already exited. 1.16 - kill -TERM `cat ${tmp}/* | tr '\n' ' '` 2> /dev/null 1.17 - wait 1.18 - echo Interrupt complete! 1.19 - fi 1.20 + kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null 1.21 + wait 1.22 + echo Interrupt complete! 1.23 + fi 1.24 fi 1.25 rm -f -r ${tmp} 1.26 exit 1 1.27 } 1.28 1.29 nice_exit () { 1.30 - if [ -d ${tmp} ]; then 1.31 - if [ "`ls ${tmp}`" != "" ]; then 1.32 - wait 1.33 - fi 1.34 + if [ -d ${tmp} ]; then 1.35 + if [ "`ls ${tmp}`" != "" ]; then 1.36 + wait 1.37 + fi 1.38 fi 1.39 rm -f -r ${tmp} 1.40 } 1.41 1.42 trap 'safe_interrupt' INT QUIT 1.43 trap 'nice_exit' EXIT 1.44 - 1.45 + 1.46 # Only look in specific locations for possible forests (avoids long searches) 1.47 pull_default="" 1.48 repos="" 1.49 @@ -172,14 +172,26 @@ 1.50 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.51 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.52 echo ${hg} clone ${pull_newrepo} ${i} 1.53 - ${hg} clone ${pull_newrepo} ${i} & 1.54 + path="`dirname ${i}`" 1.55 + if [ "${path}" != "." ] ; then 1.56 + times=0 1.57 + while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists 1.58 + do 1.59 + times=`expr ${times} '+' 1` 1.60 + if [ `expr ${times} '%' 10` -eq 0 ] ; then 1.61 + echo ${path} still not created, waiting... 1.62 + fi 1.63 + sleep 5 1.64 + done 1.65 + fi 1.66 + (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 1.67 else 1.68 echo "cd ${i} && ${hg} $*" 1.69 - cd ${i} && ${hg} "$@" & 1.70 - fi 1.71 + cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 1.72 + fi 1.73 echo $! > ${tmp}/${repopidfile}.pid 1.74 ) 2>&1 | sed -e "s@^@${reponame}: @") & 1.75 - 1.76 + 1.77 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.78 sleep 2 1.79 echo Waiting 5 secs before spawning next background command. 1.80 @@ -189,6 +201,15 @@ 1.81 # Wait for all hg commands to complete 1.82 wait 1.83 1.84 -# Terminate with exit 0 all the time (hard to know when to say "failed") 1.85 -exit 0 1.86 - 1.87 +# Terminate with exit 0 only if all subprocesses were successful 1.88 +ec=0 1.89 +if [ -d ${tmp} ]; then 1.90 + for rc in ${tmp}/*.pid.rc ; do 1.91 + exit_code=`cat ${rc} | tr -d ' \n\r'` 1.92 + if [ "${exit_code}" != "0" ] ; then 1.93 + echo "WARNING: ${rc} exited abnormally." 1.94 + ec=1 1.95 + fi 1.96 + done 1.97 +fi 1.98 +exit ${ec}
2.1 --- a/get_source.sh Thu Jan 31 17:04:19 2013 -0800 2.2 +++ b/get_source.sh Wed Feb 06 11:36:19 2013 +0000 2.3 @@ -26,7 +26,7 @@ 2.4 # 2.5 2.6 # Get clones of all nested repositories 2.7 -sh ./common/bin/hgforest.sh clone "$@" 2.8 +sh ./common/bin/hgforest.sh clone "$@" || exit 1 2.9 2.10 # Update all existing repositories to the latest sources 2.11 sh ./common/bin/hgforest.sh pull -u