From 84f266568d09bd47bdcbd7e3cb449b4e7f7bc77e Mon Sep 17 00:00:00 2001 From: deajan Date: Sat, 22 Oct 2016 14:14:52 +0200 Subject: [PATCH] pidState command busybox compat --- dev/ofunctions.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 447060a..e3c8459 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,6 +1,6 @@ #### MINIMAL-FUNCTION-SET BEGIN #### -## FUNC_BUILD=2016102102 +## FUNC_BUILD=2016102201 ## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## To use in a program, define the following variables: @@ -684,8 +684,10 @@ function WaitForTaskCompletion { if [ $(IsInteger $pid) -eq 1 ]; then 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) + #TODO(high): have this tested on *BSD, Mac, Win & busybox. + #TODO(high): propagate changes to ParallelExec + #pidState=$(ps -p$pid -o state= 2 > /dev/null) + pidState="$(eval $PROCESS_STATE_CMD)" if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then newPidsArray+=($pid) fi @@ -791,7 +793,8 @@ function ParallelExec { if [ $(IsInteger $pid) -eq 1 ]; then # Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :) if kill -0 $pid > /dev/null 2>&1; then - pidState=$(ps -p$pid -o state= 2 > /dev/null) + #pidState=$(ps -p$pid -o state= 2 > /dev/null) + pidState="$(eval $PROCESS_STATE_CMD)" if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then newPidsArray+=($pid) fi @@ -1487,6 +1490,12 @@ function InitLocalOSSettings { PING_CMD="ping -c 2 -i .2" fi + if [ "$LOCAL_OS" == "busybox" ]; then + PROCESS_STATE_CMD="echo none" + else + PROCESS_STATE_CMD='ps -p$pid -o state= 2 > /dev/null' + fi + ## Stat command has different syntax on Linux and FreeBSD/MacOSX if [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BSD" ]; then STAT_CMD="stat -f \"%Sm\""