From 432c7d836430bb9b7c15962ab2cef123997bb66e Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 31 Jan 2018 20:54:16 +0100 Subject: [PATCH] fixed bind-input/output --- bind-input | 13 ++++++++----- bind-output | 16 ++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bind-input b/bind-input index 296f42d..8379c41 100755 --- a/bind-input +++ b/bind-input @@ -37,8 +37,8 @@ touch $BUFFER; ( echo " > binding port $IN_PT to $BUFFER"; + trap "kill -9 $NC_PID 2>/dev/null; exit 1;" HUP INT KILL TERM; - trap "kill -9 $NC_PID 2>/dev/null" INT KILL; infail=0; # (1) kill script after 10 failures @@ -61,7 +61,7 @@ touch $BUFFER; # (5) Bind input infail="0"; - ( nc -lp $IN_PT >> $BUFFER 2>/dev/null )& + nc -lp $IN_PT >> $BUFFER 2>/dev/null& NC_PID=$!; wait $NC_PID; @@ -74,10 +74,13 @@ LOOP_PID=$!; # (2) Remove buffer + kill loop # on_exit(){ echo " < closing binding port $IN_PT to $BUFFER"; - rm $BUFFER 2>/dev/null; - kill -9 $LOOP_PID 2>/dev/null; + rm $BUFFER 2>/dev/null && echo " < $BUFFER deleted"; + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; } -trap "on_exit;" INT KILL; +trap "on_exit;" HUP INT KILL TERM; wait $LOOP_PID; diff --git a/bind-output b/bind-output index 46c1d80..2ee442b 100755 --- a/bind-output +++ b/bind-output @@ -37,8 +37,8 @@ touch $BUFFER; #--------------------------------------------------------# ( echo " > binding $BUFFER to $OUT_IP:$OUT_PT"; + trap "kill -9 $NC_PID 2>/dev/null; exit 1;" HUP INT KILL TERM; - trap "kill -9 %1 2>/dev/null" INT KILL; outfail=0; # (1) kill script after 10 failures @@ -61,8 +61,9 @@ touch $BUFFER; # (5) Bind output outfail="0"; - ( tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null )& - wait $!; + tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null & + NC_PID=$!; + wait $NC_PID; done; @@ -73,10 +74,13 @@ LOOP_PID=$!; # (2) Remove buffer + kill loop # on_exit(){ echo " < closing binding from $BUFFER to $OUT_IP:$OUT_PT"; - rm $BUFFER 2>/dev/null; - kill -9 $LOOP_PID 2>/dev/null; + rm $BUFFER 2>/dev/null && echo " < $BUFFER deleted"; + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; } -trap "on_exit;" INT KILL; +trap "on_exit;" HUP INT KILL TERM; wait $LOOP_PID;