]> sourceware.org Git - systemtap.git/commitdiff
Add a locking file while writing the rule in stapbm script
authorLukas Berk <lberk@redhat.com>
Sat, 27 Apr 2013 17:39:36 +0000 (13:39 -0400)
committerLukas Berk <lberk@redhat.com>
Wed, 1 May 2013 15:13:36 +0000 (11:13 -0400)
*java/stapbm: at times there are several rules being written so quickly
      that the script overlaps the rules, resulting in an errnous
      script, add a lock file to ensure this doesn't happen

java/stapbm

index 1d5fe02fc248dc4c02093f7fe17fd135f2c8ebaf..6507309ff286fc36181b8ac8d64ced63edde977d 100755 (executable)
 #This is to avoid recurssion in probing java processes
 FILE=`hostname`-$$
 JAVA_FILE=`hostname`-`jps -l | grep $3 | cut -f1 -d" "`
+
+function write_rule()
+{
+    if [[ ! -f "$2/java/$4-lock" ]]
+    then
+       touch $2/java/$4-lock
+       echo "RULE $4" >> $2/java/$4-tmp.btm
+       echo "CLASS $5" >> $2/java/$4-tmp.btm
+       echo "METHOD $6" >> $2/java/$4-tmp.btm
+       echo "HELPER HelperSDT" >> $2/java/$4-tmp.btm
+        #at what begin, end, line?
+       script_invocation_location $8 $2 $4
+       echo "IF TRUE" >> $2/java/$4-tmp.btm
+        # stap helper method switch statement
+       print_stap_helper $7 $5 $6 $2 $4
+       echo "ENDRULE" >> $2/java/$4-tmp.btm
+
+       if [ -f $2/java/$4.btm ]
+       then
+           DIFF=$(diff $2/java/$4.btm $2/java/$4-tmp.btm)
+           if [ "$DIFF" != "" ]
+           then
+               cat $2/java/$4-tmp.btm > $2/java/$4.btm
+               rm $2/java/$4-lock 2>/dev/null 1>/dev/null
+               exit
+           else
+               if [ -f $2/java/$JAVA_FILE ]
+               then
+                   rm $2/java/$4-lock 2>/dev/null 1>/dev/null
+                   exit
+               fi
+           fi
+       else
+           cp $2/java/$4-tmp.btm $2/java/$4.btm
+           rm $2/java/$4-lock 2>/dev/null 1>/dev/null
+       fi
+    else
+       sleep 0.5
+       write_rule $1 $2 $3 $4 $5 $6 $7 $8
+    fi
+
+}
 function install_byteman()
 {
     if [[ ! -f "$4/java/$JAVA_FILE" && ! -f $4/java/`hostname`-install ]]
@@ -147,33 +189,5 @@ function print_stap_helper
 
 mkdir -p $2/java
 check_running $2 $3 $5 $6
-echo "RULE $4" >> $2/java/$4-tmp.btm
-echo "CLASS $5" >> $2/java/$4-tmp.btm
-echo "METHOD $6" >> $2/java/$4-tmp.btm
-echo "HELPER HelperSDT" >> $2/java/$4-tmp.btm
-# at what begin, end, line?
-script_invocation_location $8 $2 $4
-
-echo "IF TRUE" >> $2/java/$4-tmp.btm
-# stap helper method switch statement
-print_stap_helper $7 $5 $6 $2 $4
-echo "ENDRULE" >> $2/java/$4-tmp.btm
-
-if [ -f $2/java/$4.btm ]
-then
-    DIFF=$(diff $2/java/$4.btm $2/java/$4-tmp.btm)
-    if [ "$DIFF" != "" ]
-    then
-       cat $2/java/$4-tmp.btm > $2/java/$4.btm
-       exit
-    else
-       if [ -f $2/java/$JAVA_FILE ]
-       then
-           exit
-       fi
-    fi
-else
-    cp $2/java/$4-tmp.btm $2/java/$4.btm
-fi
-
+write_rule $1 $2 $3 $4 $5 $6 $7 $8
 run_byteman $1 $3 $4 $2
This page took 0.031242 seconds and 5 git commands to generate.