[Swift-commit] r4096 - SwiftApps/SwiftR/Swift/exec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Tue Feb 15 11:23:41 CST 2011


Author: tga
Date: 2011-02-15 11:23:41 -0600 (Tue, 15 Feb 2011)
New Revision: 4096

Modified:
   SwiftApps/SwiftR/Swift/exec/fifowrite
Log:
Fix to prevent fifowrite processes breeding out of control: signal is now
caught so if an apply call is Ctrl-Ced then the fifo write shell will clean up properly.


Modified: SwiftApps/SwiftR/Swift/exec/fifowrite
===================================================================
--- SwiftApps/SwiftR/Swift/exec/fifowrite	2011-02-15 02:08:21 UTC (rev 4095)
+++ SwiftApps/SwiftR/Swift/exec/fifowrite	2011-02-15 17:23:41 UTC (rev 4096)
@@ -33,6 +33,16 @@
     esac
 done
 
+function cleanup() {
+    if [ "$tout_pid" != "" ]; then
+        # stop timeout process from lingering
+        kill $tout_pid &> /dev/null
+    fi
+    if [ "$catpid" != ""  ]; then
+        kill $catpid &> /dev/null
+    fi    
+}
+
 # fork off a process to read from fifo and write to
 # temp file.
 # echo message to fifo, fork off a process.  The remainder
@@ -41,6 +51,7 @@
 echo -n "$msg" > "$fifo" &
 catpid=$!
 tout_pid=""
+
 if [ "$timeout" -gt 0 ];
 then
     stimeout=`echo "scale=3; $timeout/1000.0" | bc`
@@ -54,17 +65,18 @@
     ) &> /dev/null &
     tout_pid=$!
 fi
+
 # ignore kill signal when child is killed: 
 # at that time wait will wake up and we can exit normally
 trap "" 15
 if wait $catpid
 then
+    catpid=""
     # cat exited normally
-    if [ ! "$tout_pid" = "" ]; then
-        # stop timeout process from lingering
-        kill $tout_pid &> /dev/null
-    fi
+    cleanup
     exit 0
 else
+    catpid=""
+    cleanup
     exit 2
 fi




More information about the Swift-commit mailing list