annotate common/bin/hgforest.sh @ 2397:27810b5e38a4

8169925: Organize licenses by module in source, JMOD file, and run-time image Reviewed-by: alanb, erikj, ihse, naoto, prr Contributed-by: mandy.chung@oracle.com, jeannette.hung@oracle.com
author mchung
date Mon, 12 Dec 2016 18:56:32 -0800
parents dbcc37629404
children 96a95d5c0a08
rev   line source
mduigou@1007 1 #!/bin/sh
ohrstrom@536 2 #
ihse@2305 3 # Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
ohrstrom@536 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohrstrom@536 5 #
ohrstrom@536 6 # This code is free software; you can redistribute it and/or modify it
ohrstrom@536 7 # under the terms of the GNU General Public License version 2 only, as
ohrstrom@536 8 # published by the Free Software Foundation.
ohrstrom@536 9 #
ohrstrom@536 10 # This code is distributed in the hope that it will be useful, but WITHOUT
ohrstrom@536 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohrstrom@536 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohrstrom@536 13 # version 2 for more details (a copy is included in the LICENSE file that
ohrstrom@536 14 # accompanied this code).
ohrstrom@536 15 #
ohrstrom@536 16 # You should have received a copy of the GNU General Public License version
ohrstrom@536 17 # 2 along with this work; if not, write to the Free Software Foundation,
ohrstrom@536 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohrstrom@536 19 #
ohrstrom@536 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohrstrom@536 21 # or visit www.oracle.com if you need additional information or have any
ohrstrom@536 22 # questions.
ohrstrom@536 23 #
ohrstrom@536 24
mduigou@1045 25 # Shell script for a fast parallel forest/trees command
ohrstrom@536 26
mduigou@1045 27 usage() {
mduigou@1045 28 echo "usage: $0 [-h|--help] [-q|--quiet] [-v|--verbose] [-s|--sequential] [--] <command> [commands...]" > ${status_output}
prr@1378 29 echo "command format : mercurial-command [ "jdk" ] [ extra-url ]"
prr@1378 30 echo "command option: jdk : used only with clone command to request just the extra repos for JDK-only builds"
prr@1378 31 echo "command option : extra-url : server hosting the extra repositories"
mduigou@1045 32 echo "Environment variables which modify behaviour:"
mduigou@1045 33 echo " HGFOREST_QUIET : (boolean) If 'true' then standard output is redirected to /dev/null"
mduigou@1045 34 echo " HGFOREST_VERBOSE : (boolean) If 'true' then Mercurial asked to produce verbose output"
mduigou@1045 35 echo " HGFOREST_SEQUENTIAL : (boolean) If 'true' then repos are processed sequentially. Disables concurrency"
mduigou@1045 36 echo " HGFOREST_GLOBALOPTS : (string, must begin with space) Additional Mercurial global options"
mduigou@1045 37 echo " HGFOREST_REDIRECT : (file path) Redirect standard output to specified file"
mduigou@1045 38 echo " HGFOREST_FIFOS : (boolean) Default behaviour for FIFO detection. Does not override FIFOs disabled"
mduigou@1045 39 echo " HGFOREST_CONCURRENCY: (positive integer) Number of repos to process concurrently"
mduigou@1045 40 echo " HGFOREST_DEBUG : (boolean) If 'true' then temp files are retained"
mduigou@1045 41 exit 1
mduigou@1045 42 }
mduigou@1045 43
mduigou@1045 44 global_opts="${HGFOREST_GLOBALOPTS:-}"
mduigou@1045 45 status_output="${HGFOREST_REDIRECT:-/dev/stdout}"
mduigou@1045 46 qflag="${HGFOREST_QUIET:-false}"
mduigou@1045 47 vflag="${HGFOREST_VERBOSE:-false}"
mduigou@1045 48 sflag="${HGFOREST_SEQUENTIAL:-false}"
mduigou@1005 49 while [ $# -gt 0 ]
mduigou@1005 50 do
mduigou@1005 51 case $1 in
mduigou@1045 52 -h | --help )
mduigou@1045 53 usage
mduigou@1045 54 ;;
mduigou@1045 55
mduigou@1005 56 -q | --quiet )
mduigou@1005 57 qflag="true"
mduigou@1005 58 ;;
mduigou@1005 59
mduigou@1005 60 -v | --verbose )
mduigou@1005 61 vflag="true"
mduigou@1005 62 ;;
mduigou@1005 63
chegar@1016 64 -s | --sequential )
chegar@1016 65 sflag="true"
chegar@1016 66 ;;
chegar@1016 67
mduigou@1005 68 '--' ) # no more options
mduigou@1005 69 shift; break
mduigou@1005 70 ;;
mduigou@1005 71
mduigou@1005 72 -*) # bad option
mduigou@1005 73 usage
mduigou@1005 74 ;;
mduigou@1005 75
mduigou@1005 76 * ) # non option
mduigou@1005 77 break
mduigou@1005 78 ;;
mduigou@1005 79 esac
mduigou@1005 80 shift
mduigou@1005 81 done
mduigou@1005 82
mduigou@1133 83 # debug mode
mduigou@1133 84 if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
mduigou@1133 85 global_opts="${global_opts} --debug"
mduigou@1133 86 fi
mduigou@1133 87
mduigou@1045 88 # silence standard output?
mduigou@1045 89 if [ ${qflag} = "true" ] ; then
mduigou@1045 90 global_opts="${global_opts} -q"
mduigou@1045 91 status_output="/dev/null"
mduigou@1045 92 fi
mduigou@1005 93
mduigou@1045 94 # verbose output?
mduigou@1045 95 if [ ${vflag} = "true" ] ; then
mduigou@1045 96 global_opts="${global_opts} -v"
mduigou@1045 97 fi
mduigou@1005 98
mduigou@1045 99 # Make sure we have a command.
mduigou@1133 100 if [ ${#} -lt 1 -o -z "${1:-}" ] ; then
mduigou@1133 101 echo "ERROR: No command to hg supplied!" > ${status_output}
mduigou@1133 102 usage > ${status_output}
ohrstrom@536 103 fi
ohrstrom@536 104
mduigou@1133 105 # grab command
mduigou@1133 106 command="${1}"; shift
mduigou@1133 107
mduigou@1133 108 if [ ${vflag} = "true" ] ; then
mduigou@1133 109 echo "# Mercurial command: ${command}" > ${status_output}
mduigou@1133 110 fi
mduigou@1133 111
smarks@1260 112 # At this point all command options and args are in "$@".
smarks@1260 113 # Always use "$@" (within double quotes) to avoid breaking
smarks@1260 114 # args with spaces into separate args.
mduigou@1034 115
mduigou@1133 116 if [ ${vflag} = "true" ] ; then
smarks@1260 117 echo "# Mercurial command argument count: $#" > ${status_output}
smarks@1260 118 for cmdarg in "$@" ; do
smarks@1260 119 echo "# Mercurial command argument: ${cmdarg}" > ${status_output}
smarks@1260 120 done
mduigou@1133 121 fi
mduigou@1133 122
ohrstrom@536 123 # Clean out the temporary directory that stores the pid files.
ohrstrom@536 124 tmp=/tmp/forest.$$
ohrstrom@536 125 rm -f -r ${tmp}
ohrstrom@536 126 mkdir -p ${tmp}
ohrstrom@536 127
mduigou@1045 128
mduigou@1045 129 if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
mduigou@1133 130 # ignores redirection.
mduigou@1133 131 echo "DEBUG: temp files are in: ${tmp}" >&2
mduigou@1045 132 fi
mduigou@1045 133
mduigou@1045 134 # Check if we can use fifos for monitoring sub-process completion.
mduigou@1045 135 echo "1" > ${tmp}/read
mduigou@1045 136 while_subshell=1
mduigou@1045 137 while read line; do
mduigou@1045 138 while_subshell=0
mduigou@1045 139 break;
mduigou@1045 140 done < ${tmp}/read
mduigou@1045 141 rm ${tmp}/read
mduigou@1045 142
mduigou@1045 143 on_windows=`uname -s | egrep -ic -e 'cygwin|msys'`
mduigou@1045 144
mduigou@1045 145 if [ ${while_subshell} = "1" -o ${on_windows} = "1" ]; then
mduigou@1045 146 # cygwin has (2014-04-18) broken (single writer only) FIFOs
mduigou@1045 147 # msys has (2014-04-18) no FIFOs.
mduigou@1045 148 # older shells create a sub-shell for redirect to while
mduigou@1045 149 have_fifos="false"
mduigou@1045 150 else
mduigou@1045 151 have_fifos="${HGFOREST_FIFOS:-true}"
mduigou@1045 152 fi
mduigou@1045 153
ohrstrom@536 154 safe_interrupt () {
chegar@613 155 if [ -d ${tmp} ]; then
chegar@613 156 if [ "`ls ${tmp}/*.pid`" != "" ]; then
mduigou@1045 157 echo "Waiting for processes ( `cat ${tmp}/.*.pid ${tmp}/*.pid 2> /dev/null | tr '\n' ' '`) to terminate nicely!" > ${status_output}
ohrstrom@536 158 sleep 1
ohrstrom@536 159 # Pipe stderr to dev/null to silence kill, that complains when trying to kill
ohrstrom@536 160 # a subprocess that has already exited.
chegar@613 161 kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null
chegar@613 162 wait
mduigou@1005 163 echo "Interrupt complete!" > ${status_output}
chegar@613 164 fi
mduigou@1005 165 rm -f -r ${tmp}
ohrstrom@536 166 fi
mduigou@1005 167 exit 130
ohrstrom@536 168 }
ohrstrom@536 169
ohrstrom@536 170 nice_exit () {
chegar@613 171 if [ -d ${tmp} ]; then
mduigou@1045 172 if [ "`ls -A ${tmp} 2> /dev/null`" != "" ]; then
chegar@613 173 wait
chegar@613 174 fi
mduigou@1045 175 if [ "${HGFOREST_DEBUG:-false}" != "true" ] ; then
mduigou@1045 176 rm -f -r ${tmp}
mduigou@1045 177 fi
ohrstrom@536 178 fi
ohrstrom@536 179 }
ohrstrom@536 180
ohrstrom@536 181 trap 'safe_interrupt' INT QUIT
ohrstrom@536 182 trap 'nice_exit' EXIT
chegar@613 183
mduigou@1005 184 subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
prr@1378 185 jdk_subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed"
prr@1378 186 subrepos_extra="$jdk_subrepos_extra deploy install sponsors pubs"
mduigou@1005 187
ohrstrom@536 188 # Only look in specific locations for possible forests (avoids long searches)
ohrstrom@536 189 pull_default=""
ohrstrom@536 190 repos=""
ohrstrom@536 191 repos_extra=""
mduigou@1007 192 if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
mduigou@1045 193 # we must be a clone
mduigou@1007 194 if [ ! -f .hg/hgrc ] ; then
mduigou@1005 195 echo "ERROR: Need initial repository to use this script" > ${status_output}
ohrstrom@536 196 exit 1
ohrstrom@536 197 fi
mduigou@1007 198
mduigou@1045 199 # the clone must know where it came from (have a default pull path).
mduigou@1007 200 pull_default=`hg paths default`
mduigou@1007 201 if [ "${pull_default}" = "" ] ; then
mduigou@1007 202 echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
mduigou@1007 203 exit 1
mduigou@1007 204 fi
mduigou@1007 205
mduigou@1045 206 # determine which sub repos need to be cloned.
ohrstrom@536 207 for i in ${subrepos} ; do
ohrstrom@536 208 if [ ! -f ${i}/.hg/hgrc ] ; then
ohrstrom@536 209 repos="${repos} ${i}"
ohrstrom@536 210 fi
ohrstrom@536 211 done
mduigou@1041 212
mduigou@1041 213 pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
mduigou@1041 214
smarks@1260 215 if [ $# -gt 0 ] ; then
prr@1378 216 if [ "x${1}" = "xjdk" ] ; then
prr@1378 217 subrepos_extra=$jdk_subrepos_extra
prr@1378 218 echo "subrepos being cloned are $subrepos_extra"
prr@1378 219 shift
prr@1378 220 fi
mduigou@1045 221 # if there is an "extra sources" path then reparent "extra" repos to that path
mduigou@1007 222 if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
mduigou@1007 223 echo "ERROR: Need initial clone from non-local source" > ${status_output}
mduigou@1007 224 exit 1
mduigou@1007 225 fi
smarks@1260 226 # assume that "extra sources" path is the first arg
smarks@1260 227 pull_extra="${1}/${pull_default_tail}"
mduigou@1045 228
mduigou@1045 229 # determine which extra subrepos need to be cloned.
ohrstrom@536 230 for i in ${subrepos_extra} ; do
ohrstrom@536 231 if [ ! -f ${i}/.hg/hgrc ] ; then
ohrstrom@536 232 repos_extra="${repos_extra} ${i}"
ohrstrom@536 233 fi
ohrstrom@536 234 done
mduigou@1041 235 else
mduigou@1041 236 if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
mduigou@1045 237 # local source repo. Clone the "extra" subrepos that exist there.
mduigou@1041 238 for i in ${subrepos_extra} ; do
mduigou@1041 239 if [ -f ${pull_default}/${i}/.hg/hgrc -a ! -f ${i}/.hg/hgrc ] ; then
mduigou@1041 240 # sub-repo there in source but not here
mduigou@1041 241 repos_extra="${repos_extra} ${i}"
mduigou@1041 242 fi
mduigou@1041 243 done
mduigou@1041 244 fi
ohrstrom@536 245 fi
mduigou@1045 246
ohrstrom@536 247 # Any repos to deal with?
ohrstrom@536 248 if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
mduigou@1005 249 echo "No repositories to process." > ${status_output}
ohrstrom@536 250 exit
ohrstrom@536 251 fi
mduigou@1045 252
mduigou@1045 253 # Repos to process concurrently. Clone does better with low concurrency.
mduigou@1045 254 at_a_time="${HGFOREST_CONCURRENCY:-2}"
ohrstrom@536 255 else
mduigou@1045 256 # Process command for all of the present repos
mduigou@1005 257 for i in . ${subrepos} ${subrepos_extra} ; do
mduigou@1005 258 if [ -d ${i}/.hg ] ; then
mduigou@1005 259 repos="${repos} ${i}"
mduigou@1005 260 fi
ohrstrom@536 261 done
mduigou@1005 262
mduigou@1005 263 # Any repos to deal with?
mduigou@1005 264 if [ "${repos}" = "" ] ; then
mduigou@1005 265 echo "No repositories to process." > ${status_output}
mduigou@1005 266 exit
mduigou@1005 267 fi
mduigou@1005 268
mduigou@1005 269 # any of the repos locked?
mduigou@1045 270 locked=""
ohrstrom@536 271 for i in ${repos} ; do
ohrstrom@536 272 if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then
ohrstrom@536 273 locked="${i} ${locked}"
ohrstrom@536 274 fi
ohrstrom@536 275 done
mduigou@1005 276 if [ "${locked}" != "" ] ; then
mduigou@1005 277 echo "ERROR: These repositories are locked: ${locked}" > ${status_output}
mduigou@1005 278 exit 1
mduigou@1005 279 fi
mduigou@1045 280
mduigou@1045 281 # Repos to process concurrently.
mduigou@1045 282 at_a_time="${HGFOREST_CONCURRENCY:-8}"
ohrstrom@536 283 fi
ohrstrom@536 284
ohrstrom@536 285 # Echo out what repositories we do a command on.
mduigou@1005 286 echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
ohrstrom@536 287
mduigou@1005 288 if [ "${command}" = "serve" ] ; then
mduigou@1045 289 # "serve" is run for all the repos as one command.
mduigou@1005 290 (
mduigou@1005 291 (
mduigou@1045 292 cwd=`pwd`
mduigou@1045 293 serving=`basename ${cwd}`
mduigou@1005 294 (
mduigou@1005 295 echo "[web]"
mduigou@1045 296 echo "description = ${serving}"
mduigou@1005 297 echo "allow_push = *"
mduigou@1005 298 echo "push_ssl = False"
mduigou@1005 299
mduigou@1005 300 echo "[paths]"
mduigou@1045 301 for i in ${repos} ; do
mduigou@1005 302 if [ "${i}" != "." ] ; then
mduigou@1045 303 echo "/${serving}/${i} = ${i}"
mduigou@1005 304 else
mduigou@1045 305 echo "/${serving} = ${cwd}"
mduigou@1005 306 fi
mduigou@1005 307 done
mduigou@1005 308 ) > ${tmp}/serve.web-conf
mduigou@1005 309
mduigou@1045 310 echo "serving root repo ${serving}" > ${status_output}
mduigou@1005 311
mduigou@1045 312 echo "hg${global_opts} serve" > ${status_output}
mduigou@1005 313 (PYTHONUNBUFFERED=true hg${global_opts} serve -A ${status_output} -E ${status_output} --pid-file ${tmp}/serve.pid --web-conf ${tmp}/serve.web-conf; echo "$?" > ${tmp}/serve.pid.rc ) 2>&1 &
mduigou@1005 314 ) 2>&1 | sed -e "s@^@serve: @" > ${status_output}
mduigou@1005 315 ) &
mduigou@1005 316 else
mduigou@1005 317 # Run the supplied command on all repos in parallel.
mduigou@1034 318
mduigou@1034 319 # n is the number of subprocess started or which might still be running.
mduigou@1005 320 n=0
mduigou@1045 321 if [ ${have_fifos} = "true" ]; then
mduigou@1034 322 # if we have fifos use them to detect command completion.
mduigou@1034 323 mkfifo ${tmp}/fifo
mduigou@1034 324 exec 3<>${tmp}/fifo
mduigou@1034 325 fi
mduigou@1034 326
mduigou@1045 327 # iterate over all of the subrepos.
mduigou@1005 328 for i in ${repos} ${repos_extra} ; do
mduigou@1005 329 n=`expr ${n} '+' 1`
mduigou@1005 330 repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
mduigou@1005 331 reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
mduigou@1005 332 pull_base="${pull_default}"
mduigou@1045 333
mduigou@1045 334 # regular repo or "extra" repo?
mduigou@1045 335 for j in ${repos_extra} ; do
mduigou@1045 336 if [ "${i}" = "${j}" ] ; then
mduigou@1045 337 # it's an "extra"
erikj@2203 338 if [ -n "${pull_extra}" ]; then
erikj@2203 339 # if no pull_extra is defined, assume that pull_default is valid
erikj@2203 340 pull_base="${pull_extra}"
erikj@2203 341 fi
ohrstrom@536 342 fi
mduigou@1005 343 done
mduigou@1045 344
mduigou@1045 345 # remove trailing slash
mduigou@1034 346 pull_base="`echo ${pull_base} | sed -e 's@[/]*$@@'`"
mduigou@1045 347
mduigou@1045 348 # execute the command on the subrepo
mduigou@1005 349 (
mduigou@1005 350 (
mduigou@1007 351 if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
mduigou@1045 352 # some form of clone
mduigou@1045 353 clone_newrepo="${pull_base}/${i}"
mduigou@1045 354 parent_path="`dirname ${i}`"
mduigou@1045 355 if [ "${parent_path}" != "." ] ; then
mduigou@1005 356 times=0
mduigou@1045 357 while [ ! -d "${parent_path}" ] ; do ## nested repo, ensure containing dir exists
mduigou@1045 358 if [ "${sflag}" = "true" ] ; then
mduigou@1045 359 # Missing parent is fatal during sequential operation.
mduigou@1045 360 echo "ERROR: Missing parent path: ${parent_path}" > ${status_output}
mduigou@1045 361 exit 1
mduigou@1045 362 fi
mduigou@1046 363 times=`expr ${times} '+' 1`
mduigou@1005 364 if [ `expr ${times} '%' 10` -eq 0 ] ; then
mduigou@1045 365 echo "${parent_path} still not created, waiting..." > ${status_output}
mduigou@1005 366 fi
mduigou@1005 367 sleep 5
mduigou@1005 368 done
mduigou@1005 369 fi
mduigou@1045 370 # run the clone command.
mduigou@1045 371 echo "hg${global_opts} clone ${clone_newrepo} ${i}" > ${status_output}
mduigou@1045 372 (PYTHONUNBUFFERED=true hg${global_opts} clone ${clone_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
mduigou@1005 373 else
mduigou@1045 374 # run the command.
smarks@1260 375 echo "cd ${i} && hg${global_opts} ${command} ${@}" > ${status_output}
smarks@1260 376 cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} "${@}"; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
mduigou@1005 377 fi
mduigou@1005 378
mduigou@1005 379 echo $! > ${tmp}/${repopidfile}.pid
mduigou@1005 380 ) 2>&1 | sed -e "s@^@${reponame}: @" > ${status_output}
mduigou@1045 381 # tell the fifo waiter that this subprocess is done.
mduigou@1045 382 if [ ${have_fifos} = "true" ]; then
mduigou@1045 383 echo "${i}" >&3
mduigou@1034 384 fi
mduigou@1005 385 ) &
mduigou@1005 386
mduigou@1045 387 if [ "${sflag}" = "true" ] ; then
mduigou@1045 388 # complete this task before starting another.
mduigou@1045 389 wait
mduigou@1034 390 else
mduigou@1045 391 if [ "${have_fifos}" = "true" ]; then
mduigou@1045 392 # check on count of running subprocesses and possibly wait for completion
mduigou@1045 393 if [ ${n} -ge ${at_a_time} ] ; then
mduigou@1045 394 # read will block until there are completed subprocesses
mduigou@1045 395 while read repo_done; do
mduigou@1045 396 n=`expr ${n} '-' 1`
mduigou@1045 397 if [ ${n} -lt ${at_a_time} ] ; then
mduigou@1045 398 # we should start more subprocesses
mduigou@1045 399 break;
mduigou@1045 400 fi
mduigou@1045 401 done <&3
mduigou@1045 402 fi
mduigou@1045 403 else
mduigou@1034 404 # Compare completions to starts
mduigou@1045 405 completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
mduigou@1045 406 while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do
mduigou@1034 407 # sleep a short time to give time for something to complete
mduigou@1034 408 sleep 1
mduigou@1045 409 completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
mduigou@1034 410 done
mduigou@1034 411 fi
chegar@1016 412 fi
ohrstrom@536 413 done
mduigou@1133 414
mduigou@1133 415 if [ ${have_fifos} = "true" ]; then
mduigou@1133 416 # done with the fifo
mduigou@1133 417 exec 3>&-
mduigou@1133 418 fi
mduigou@1005 419 fi
chegar@613 420
mduigou@1034 421 # Wait for all subprocesses to complete
ohrstrom@536 422 wait
ohrstrom@536 423
chegar@613 424 # Terminate with exit 0 only if all subprocesses were successful
mduigou@1133 425 # Terminate with highest exit code of subprocesses
chegar@613 426 ec=0
chegar@613 427 if [ -d ${tmp} ]; then
mduigou@1045 428 rcfiles="`(ls -a ${tmp}/*.pid.rc 2> /dev/null) || echo ''`"
mduigou@1045 429 for rc in ${rcfiles} ; do
chegar@613 430 exit_code=`cat ${rc} | tr -d ' \n\r'`
chegar@613 431 if [ "${exit_code}" != "0" ] ; then
mduigou@1133 432 if [ ${exit_code} -gt 1 ]; then
mduigou@1133 433 # mercurial exit codes greater than "1" signal errors.
mduigou@1045 434 repo="`echo ${rc} | sed -e 's@^'${tmp}'@@' -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`"
mduigou@1045 435 echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output}
mduigou@1133 436 fi
mduigou@1133 437 if [ ${exit_code} -gt ${ec} ]; then
mduigou@1133 438 # assume that larger exit codes are more significant
mduigou@1133 439 ec=${exit_code}
mduigou@1133 440 fi
chegar@613 441 fi
chegar@613 442 done
chegar@613 443 fi
chegar@613 444 exit ${ec}