X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=scripts%2Fmidp_common.sh;h=aa500ae9a959885bd66eb8ee1cbf82426565e8ea;hb=cc2f3e22307a2ddb835c4ae15dbe5302a143653f;hp=0f767070e217639fc5b2548db0e2b315610f6608;hpb=66d21002b1ea9e439731fa624836705f8bc34847;p=clitk.git diff --git a/scripts/midp_common.sh b/scripts/midp_common.sh index 0f76707..aa500ae 100755 --- a/scripts/midp_common.sh +++ b/scripts/midp_common.sh @@ -1,4 +1,4 @@ -#! /bin/sh +x +#! /bin/sh -x ############################################################################### # @@ -9,7 +9,72 @@ # ############################################################################### +# +# check return value passed and abort if it represents an error (ie, ret != 0) +# optionally, a function can be passed as a 3rd parameter, to be called just +# before exiting. this is useful for cleaning up, for example. +# +abort_on_error() +{ + if [ $2 != 0 ]; then + echo Aborted at $1 with code $2 + if [ $# = 3 ]; then + eval $3 + fi + exit $2 + fi +} + +# +# wait for all processes in the list and return their exit codes +# in the ret_codes variable. +# +# OBS: this function must always be called in the same shell +# that launched the processes. +# +wait_pids() +{ + local pids=$* + local ret= + local rets= +# echo PIDS: $pids + for p in $pids; do +# echo waiting $p + wait $p > /dev/null 2> /dev/null + ret=$? + if [ ret != 127 ]; then + rets=$rets" "$ret + else + rets=$rets" "0 + fi + + done + + ret_codes=$rets +} + +# +# clean-up functions for maks, registration, and midp +# +clean_up_masks() +{ + rm -fr $mask_dir_tmp +} + +clean_up_midp() +{ + rm -fr $midp_dir +} + +clean_up_registration() +{ + rm -fr $vf_dir + rm -fr $output_dir +} + + +# # block execution untill the number of threads (jobs) launched by the # current process is below the given number of threads. MAX_THREADS=2