diff options
author | Bryan Drewery <bryan@shatow.net> | 2014-04-04 15:57:41 +0400 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2014-04-04 15:57:41 +0400 |
commit | 7b5cf1f8ba9a72980428fc3001132da1331027fa (patch) | |
tree | 53e0414b3c47d3d28204729c99bacffdb36a3059 /src/share | |
parent | a34a39e259e12f1c3c2d5e0fc69f1a8f473b0ade (diff) |
Move more parallel code
Diffstat (limited to 'src/share')
-rwxr-xr-x | src/share/poudriere/common.sh | 49 | ||||
-rw-r--r-- | src/share/poudriere/include/parallel.sh | 51 |
2 files changed, 51 insertions, 49 deletions
diff --git a/src/share/poudriere/common.sh b/src/share/poudriere/common.sh index 9c3f7e02..1924d0e1 100755 --- a/src/share/poudriere/common.sh +++ b/src/share/poudriere/common.sh @@ -39,55 +39,6 @@ was_a_jail_run() { was_a_bulk_run || [ "${0##*/}" = "pkgclean.sh" ] } -_wait() { - # Workaround 'wait' builtin possibly returning early due to signals - # by using 'pwait' to wait(2) and then 'wait' to collect return code - local ret=0 pid - - pwait "$@" 2>/dev/null || : - for pid in "$@"; do - wait ${pid} || ret=$? - done - - return ${ret} -} - -kill_and_wait() { - [ $# -eq 2 ] || eargs kill_and_wait time pids - local time="$1" - local pids="$2" - local ret=0 - local pid - local found_pid - local retry - - [ -z "${pids}" ] && return 0 - - # Give children $time seconds to exit and then force kill - retry=${time} - kill ${pids} 2>/dev/null || : - - while [ ${retry} -gt 0 ]; do - found_pid=0 - for pid in ${pids}; do - if kill -0 ${pid} 2>/dev/null; then - sleep 1 - found_pid=1 - break - fi - done - retry=$((retry - 1)) - [ ${found_pid} -eq 0 ] && retry=0 - done - - # Kill all children instead of waiting on them - [ ${found_pid} -eq 1 ] && kill -9 ${pids} 2>/dev/null || : - - _wait ${pids} || ret=$? - - return ${ret} -} - # Based on Shell Scripting Recipes - Chris F.A. Johnson (c) 2005 # Replace a pattern without needing a subshell/exec _gsub() { diff --git a/src/share/poudriere/include/parallel.sh b/src/share/poudriere/include/parallel.sh index 84972049..09375ffb 100644 --- a/src/share/poudriere/include/parallel.sh +++ b/src/share/poudriere/include/parallel.sh @@ -23,6 +23,57 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. +_wait() { + # Workaround 'wait' builtin possibly returning early due to signals + # by using 'pwait' to wait(2) and then 'wait' to collect return code + local ret=0 pid + + pwait "$@" 2>/dev/null || : + for pid in "$@"; do + wait ${pid} || ret=$? + done + + return ${ret} +} + + +kill_and_wait() { + [ $# -eq 2 ] || eargs kill_and_wait time pids + local time="$1" + local pids="$2" + local ret=0 + local pid + local found_pid + local retry + + [ -z "${pids}" ] && return 0 + + # Give children $time seconds to exit and then force kill + retry=${time} + kill ${pids} 2>/dev/null || : + + while [ ${retry} -gt 0 ]; do + found_pid=0 + for pid in ${pids}; do + if kill -0 ${pid} 2>/dev/null; then + sleep 1 + found_pid=1 + break + fi + done + retry=$((retry - 1)) + [ ${found_pid} -eq 0 ] && retry=0 + done + + # Kill all children instead of waiting on them + [ ${found_pid} -eq 1 ] && kill -9 ${pids} 2>/dev/null || : + + _wait ${pids} || ret=$? + + return ${ret} +} + + parallel_exec() { local cmd="$1" local ret=0 |