diff options
author | donbright <hugh.m.bright@gmail.com> | 2013-03-05 23:47:14 (GMT) |
---|---|---|
committer | donbright <hugh.m.bright@gmail.com> | 2013-03-05 23:47:14 (GMT) |
commit | 42f21c3a0850083d245aa3ac346a53e876f0679e (patch) | |
tree | facf41750e0fe27cc4cdaf352c9c8e687011d103 /tests/virtualfb.sh | |
parent | 422c668dcb538f181683ae51305bf8d3404f48d6 (diff) | |
parent | 4734172c3a16cc06b09e4d2131aa8e380bd0f226 (diff) |
Merge pull request #288 from openscad/issue11_2
Issue11 2
Diffstat (limited to 'tests/virtualfb.sh')
-rwxr-xr-x | tests/virtualfb.sh | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/virtualfb.sh b/tests/virtualfb.sh index 5abd804..186b389 100755 --- a/tests/virtualfb.sh +++ b/tests/virtualfb.sh @@ -3,8 +3,12 @@ # Toggle the Virtual Framebuffer # If started, stop. If stopped, start. +debug= + start() { + VFB_BINARY= + if [ "`command -v Xvfb`" ]; then VFB_BINARY=Xvfb fi @@ -15,12 +19,26 @@ start() if [ ! $VFB_BINARY ]; then echo "$0 Failed, cannot find Xvfb or Xvnc" + echo "$0 Failed, cannot find Xvfb or Xvnc" > ./virtualfb.log exit 1 fi VFB_DISPLAY=`echo | awk 'BEGIN{srand();} {printf ":%.0f", rand()*1000+100};'` $VFB_BINARY $VFB_DISPLAY -screen 0 800x600x24 &> ./virtualfb.log & - VFB_PID=$! + # on some systems $! gives us VFB_BINARY's PID, on others we have to subtract 1 + VFB_PID_MINUS0=$! + VFB_PID_MINUS1=$(($VFB_PID_MINUS0 - 1)) + + if [ "`ps cax | grep $VFB_PID_MINUS0 | grep $VFB_BINARY`" ]; then + VFB_PID=$VFB_PID_MINUS0 + elif [ "`ps cax | grep $VFB_PID_MINUS1 | grep $VFB_BINARY`" ]; then + VFB_PID=$VFB_PID_MINUS1 + else + echo started $VFB_BINARY but cannot find process ID in process table + echo please stop $VFB_BINARY manually + VFB_PID= + return + fi echo $VFB_DISPLAY > ./virtualfb.DISPLAY echo $VFB_PID > ./virtualfb.PID @@ -48,13 +66,29 @@ isrunning() { isrunning_result= if [ -e ./virtualfb.PID ]; then + if [ $debug ]; then echo "found PID file"; fi VFB_PID=`cat ./virtualfb.PID` + if [ ! $VFB_PID ]; then + echo ./virtualfb.PID contained invalid PID number + return + fi + if [ $debug ]; then echo "PID from file:" $VFB_PID; fi + PS_RESULT=`ps cax | awk ' { print $1 } '` + GREP_RESULT=`echo $PS_RESULT | grep $VFB_PID` + if [ $debug ]; then echo "grep ps result: " $GREP_RESULT; fi if [ "`ps cax | awk ' { print $1 } ' | grep ^$VFB_PID\$`" ]; then + if [ $debug ]; then echo "found pid in process table."; fi isrunning_result=1 + else + if [ $debug ]; then echo "did not find pid in process table."; fi fi fi } +if [ "`echo $* | grep debug`" ]; then + debug=1 +fi + isrunning if [ $isrunning_result ]; then stop |