[Swift-commit] r4103 - SwiftApps/SwiftR/Swift/exec
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Tue Feb 15 15:26:14 CST 2011
Author: tga
Date: 2011-02-15 15:26:14 -0600 (Tue, 15 Feb 2011)
New Revision: 4103
Modified:
SwiftApps/SwiftR/Swift/exec/fiforead
SwiftApps/SwiftR/Swift/exec/fifowrite
Log:
Added interrupt handler to cleanup fiforead/write processes if cancelled from R.
Modified: SwiftApps/SwiftR/Swift/exec/fiforead
===================================================================
--- SwiftApps/SwiftR/Swift/exec/fiforead 2011-02-15 19:59:52 UTC (rev 4102)
+++ SwiftApps/SwiftR/Swift/exec/fiforead 2011-02-15 21:26:14 UTC (rev 4103)
@@ -26,11 +26,28 @@
done
outfile=`mktemp`
+function cleanup {
+ if [ "$tout_pid" != "" ]; then
+ # stop timeout process from lingering
+ kill $tout_pid &> /dev/null
+ fi
+ if [ "$catpid" != "" ]; then
+ # stop timeout process from lingering
+ kill $catpid &> /dev/null
+ fi
+}
+
+
# fork off a process to read from fifo and write to
# temp file
+tout_pid=""
+catpid=""
+
cat $fifo &> "$outfile" &
+
catpid=$!
-tout_pid=""
+trap "cleanup" EXIT 1 2 3 15
+
if [ "$timeout" -gt 0 ];
then
stimeout=`echo "scale=3; $timeout/1000.0" | bc`
@@ -48,21 +65,19 @@
# are closed
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
# Print output
cat "$outfile"
rm "$outfile"
exit 0
else
+ catpid=""
+ cleanup
echo "_FIFOTIMEOUT_"
rm "$outfile"
#TODO: kill timeout thread
Modified: SwiftApps/SwiftR/Swift/exec/fifowrite
===================================================================
--- SwiftApps/SwiftR/Swift/exec/fifowrite 2011-02-15 19:59:52 UTC (rev 4102)
+++ SwiftApps/SwiftR/Swift/exec/fifowrite 2011-02-15 21:26:14 UTC (rev 4103)
@@ -51,6 +51,7 @@
echo -n "$msg" > "$fifo" &
catpid=$!
tout_pid=""
+trap "cleanup" EXIT 1 2 3 15
if [ "$timeout" -gt 0 ];
then
@@ -66,9 +67,6 @@
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=""
More information about the Swift-commit
mailing list