Attempts to write to vsys FIFO when file exists. If process is blocked, kill and...
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 19 May 2008 19:26:11 +0000 (19:26 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 19 May 2008 19:26:11 +0000 (19:26 +0000)
pf2slice-initscript

index 788e212..9ecede7 100644 (file)
@@ -4,13 +4,44 @@
 # description: planetflow slice initscript
 #
 
 # description: planetflow slice initscript
 #
 
-. /etc/rc.d/init.d/functions
+#. /etc/rc.d/init.d/functions
+
+DELTA=10 # Time to sleep between polls
+VSYSSCRIPT="/vsys/pfmount.in"
+VSYSCMD="pf"
+
+watchdog(){
+    while [ 1 ]; do
+        # if the file exists, try writing to it.
+        if [ -a ${VSYSSCRIPT} ]; then
+               echo "Writing to Fifo"
+               /bin/echo ${VSYSCMD} > ${VSYSSCRIPT} &
+               PID=$!
+               #  Wait for command to complete
+               sleep $DELTA
+               # check to see if PID is running
+               if kill -0 ${PID} >/dev/null 2>&1 ; then
+                   # if PID is running, it's likely hung.  Kill it.
+                   echo "Blocked on Fifo. Killing"
+                   kill ${PID} 
+               else
+                   # assume if PID is no longer, command completed
+                   echo "Completed. Exitting"
+                   exit 0
+               fi
+        else
+            # no pipe yet.  vsys probably hasn't started yet.  wait.
+            echo "${VSYSSCRIPT} doesn't exist"
+            sleep $DELTA
+        fi 
+    done
+}
+
 
 case "$1" in
     start)
         echo -n "starting the planetflow slice:"
 
 case "$1" in
     start)
         echo -n "starting the planetflow slice:"
-       echo "pf" > /vsys/pfmount.in
-        echo
+           watchdog 2> /dev/null
         ;;
 
     *)
         ;;
 
     *)
@@ -18,4 +49,6 @@ case "$1" in
         RETVAL=1
 esac
 
         RETVAL=1
 esac
 
+
+
 exit $RETVAL
 exit $RETVAL