Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / synfigstudio-cph-monitor
index 57ad242..6dcc2bc 100755 (executable)
@@ -17,16 +17,38 @@ trap writelog INT
 
 init()
 {
-echo "Synfig Crash Monitor is a tool to collect statistics about synfig crashes. All information is collected locally in ~/.synfig/cph directory."
+echo "SynfigStudio Crash Monitor is a tool to collect statistics about synfig crashes."
+echo "All information is collected locally in ~/.synfig/cph directory."
 echo
-echo `date +%H:%M` "Synfig Crash Monitor started."
 STARTED=0
 RUNTIME=0
 VERSION=''
 RELEASE=''
 BRANCH=''
+REVISION_ID=''
 CRASH=0
 [ ! -d ~/.synfig/cph ] && mkdir -p ~/.synfig/cph || true
+
+# Detect if crash monitor is already started
+PDIR=${0%`basename $0`}
+LCK_FILE=~/.synfig/cph/`basename $0`.lck
+if [ -f "${LCK_FILE}" ]; then
+       MYPID=`head -n 1 "${LCK_FILE}"`
+       if ! ( ps -p ${MYPID} | grep ${MYPID} >/dev/null ); then
+               # The process is not running
+               # Echo current PID into lock file
+               echo $$ > "${LCK_FILE}"
+       else
+               echo "`basename $0` is already running [${MYPID}]. Aborting."
+               sleep 5
+               exit 0
+       fi
+else
+       # The process is not running
+       # Echo current PID into lock file
+       echo $$ > "${LCK_FILE}"
+fi
+echo `date +%H:%M` "Synfig Crash Monitor started."
 }
 
 writelog()
@@ -47,7 +69,7 @@ writelog()
                        fi
                fi
                #write log
-               echo $VERSION/$BRANCH/$RELEASE $RUNTIME $CRASH >> ~/.synfig/cph/log
+               echo $VERSION/$BRANCH/$RELEASE/$REVISION_ID $RUNTIME $CRASH >> ~/.synfig/cph/log
                CRASH=0
                RUNTIME=0
        else
@@ -96,25 +118,26 @@ dumpstats()
 mainloop()
 {
        while true; do
-               if ( ps -f -u `whoami`|egrep "synfigstudio$" >/dev/null ) ; then
+               if ( ps --no-headers -f -Csynfigstudio |egrep "^`whoami`" > /dev/null ) ; then
                        #synfigstudio process exist
                        if [[ $STARTED == 0 ]]; then
                                STARTED=1
                                RUNTIME=0
                                #get version
-                               P=$(ps -f -u `whoami`|egrep "synfigstudio$"| tr -s ' '| cut -d ' ' -f 8)
+                               P=$(ps --no-headers -f -Csynfigstudio |egrep "^`whoami`" | tr -s ' '| cut -d ' ' -f 8)
                                echo 
                                if [ ! -e $P ]; then
                                        P=`which $P`
                                fi
                                P=`dirname $P`
                                VERSION=`$P/synfig --info|head -n 1|cut -d '-' -f 2`
-                               RELEASE=`$P/synfig --info|egrep "Development version:"|cut -d ' ' -f 3`
+                               RELEASE=`$P/synfig --info|egrep "Revision:"|cut -d ' ' -f 2`
                                BRANCH=`$P/synfig --info|egrep "Branch:"|cut -d ' ' -f 2-3`
+                               REVISION_ID=`$P/synfig --info|egrep "Revision ID:"|cut -d ' ' -f 3`
                                if [[ $BRANCH == '(no branch)' ]]; then
-                                       BRANCH=`$P/synfig --info|egrep "Revision ID:"|cut -d ' ' -f 3`
+                                       BRANCH=$REVISION_ID
                                fi
-                               echo `date +%H:%M` "Synfig $VERSION.$RELEASE.$BRANCH started."
+                               echo `date +%H:%M` "Synfig $VERSION.$RELEASE.$BRANCH.$REVISION_ID started."
                                echo `date +%H:%M` "Assuming Synfig installed in $P."
                        else
                                let RUNTIME=$RUNTIME+1
@@ -135,5 +158,6 @@ mainloop()
        done
 }
 
+
 init
 mainloop