From ae23418f7b0f706f338af153ce4cdee22a5bb77c Mon Sep 17 00:00:00 2001 From: deajan Date: Mon, 22 Aug 2016 08:25:47 +0200 Subject: [PATCH] Fixed signal posfix compliance --- dev/ofunctions.sh | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 787b746..e194a65 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,6 +1,6 @@ #### MINIMAL-FUNCTION-SET BEGIN #### -## FUNC_BUILD=2016081803 +## FUNC_BUILD=2016082203 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -183,7 +183,7 @@ function KillChilds { # Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing if ( [ "$self" == true ] && kill -0 $pid > /dev/null 2>&1); then Logger "Sending SIGTERM to process [$pid]." "DEBUG" - kill -s SIGTERM "$pid" + kill -s TERM "$pid" if [ $? != 0 ]; then sleep 15 Logger "Sending SIGTERM to process [$pid] failed." "DEBUG" @@ -580,7 +580,6 @@ function WaitForTaskCompletion { Logger "${FUNCNAME[0]} called by [$caller_name]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG __CheckArguments 6 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG - local soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once local log_ttime=0 # local time instance for comparaison local seconds_begin=$SECONDS # Seconds since the beginning of the script @@ -599,28 +598,6 @@ function WaitForTaskCompletion { while [ ${#pidsArray[@]} -gt 0 ]; do newPidsArray=() - for pid in "${pidsArray[@]}"; do - if kill -0 $pid > /dev/null 2>&1; then - # Handle uninterruptible sleep state or zombies by ommiting them from running process array - #TODO(high): have this tested on *BSD, Mac & Win - pidState=$(ps -p$pid -o state= 2 > /dev/null) - if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then - newPidsArray+=($pid) - fi - else - wait $pid - result=$? - if [ $result -ne 0 ]; then - errorcount=$((errorcount+1)) - Logger "${FUNCNAME[0]} called by [$caller_name] finished monitoring [$pid] with exitcode [$result]." "DEBUG" - if [ "$WAIT_FOR_TASK_COMPLETION" == "" ]; then - WAIT_FOR_TASK_COMPLETION="$pid:$result" - else - WAIT_FOR_TASK_COMPLETION=";$pid:$result" - fi - fi - fi - done Spinner if [ $counting == true ]; then @@ -641,7 +618,6 @@ function WaitForTaskCompletion { if [ $exec_time -gt $soft_max_time ]; then if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN" - soft_alert=1 SendAlert fi @@ -660,12 +636,42 @@ function WaitForTaskCompletion { fi fi + for pid in "${pidsArray[@]}"; do + if kill -0 $pid > /dev/null 2>&1; then + # Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :) + #TODO(high): have this tested on *BSD, Mac & Win + pidState=$(ps -p$pid -o state= 2 > /dev/null) + if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then + newPidsArray+=($pid) + fi + else + # pid is dead, get it's exit code from wait command + wait $pid + retval=$? + if [ $retval -ne 0 ]; then + errorcount=$((errorcount+1)) + Logger "${FUNCNAME[0]} called by [$caller_name] finished monitoring [$pid] with exitcode [$result]." "DEBUG" + if [ "$WAIT_FOR_TASK_COMPLETION" == "" ]; then + WAIT_FOR_TASK_COMPLETION="$pid:$result" + else + WAIT_FOR_TASK_COMPLETION=";$pid:$result" + fi + fi + fi + done + pidsArray=("${newPidsArray[@]}") sleep $SLEEP_TIME done Logger "${FUNCNAME[0]} ended for [$caller_name] using [$pidCount] subprocesses with [$errorcount] errors." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG - return $errorcount + + # Return exit code if only one process was monitored, else return number of errors + if [ $pidCount -eq 1 ] && [ $errorcount -eq 0 ]; then + return $errorcount + else + return $errorcount + fi } function CleanUp { @@ -983,7 +989,7 @@ function CheckConnectivity3rdPartyHosts { for i in $REMOTE_3RD_PARTY_HOSTS do eval "$PING_CMD $i > /dev/null 2>&1" & - WaitForTaskCompletion $! 10 360 ${FUNCNAME[0]} true $KEEP_LOGGING + WaitForTaskCompletion $! 180 360 ${FUNCNAME[0]} true $KEEP_LOGGING if [ $? != 0 ]; then Logger "Cannot ping 3rd party host $i" "NOTICE" else