diff --git a/bind-input b/bind-input index 2295d35..b0b4917 100755 --- a/bind-input +++ b/bind-input @@ -35,6 +35,16 @@ BUFFER="/tmp/inbuf_$IN_ID"; echo -n "" > $BUFFER; +# (3) Remove buffer + kill loop # +on_exit(){ + [[ $DEBUG ]] && echo " < closing binding port $IN_PT to $BUFFER"; + rm $BUFFER 2>/dev/null && ( [[ $DEBUG ]] && echo " < $BUFFER deleted" ); + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; +} + # (3) Launch INPUT server @@ -42,7 +52,7 @@ echo -n "" > $BUFFER; ( [[ $DEBUG ]] && 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; on_exit;" HUP INT KILL TERM; infail=0; @@ -72,18 +82,6 @@ echo -n "" > $BUFFER; )& LOOP_PID=$!; - -# (2) Remove buffer + kill loop # -on_exit(){ - [[ $DEBUG ]] && echo " < closing binding port $IN_PT to $BUFFER"; - rm $BUFFER 2>/dev/null && ( [[ $DEBUG ]] && echo " < $BUFFER deleted" ); - - kill -INT $LOOP_PID 2>/dev/null; - - exit 1; -} trap "on_exit;" HUP INT KILL TERM; -wait $LOOP_PID; - -on_exit; \ No newline at end of file +echo -n "$LOOP_PID"; \ No newline at end of file diff --git a/bind-output b/bind-output index 26ebaae..0927d6f 100755 --- a/bind-output +++ b/bind-output @@ -34,6 +34,15 @@ BUFFER="/tmp/outbuf_$OUT_ID"; # test -f $BUFFER && rm $BUFFER; echo -n "" > $BUFFER; +# (3) Remove buffer + kill loop # +on_exit(){ + [[ $DEBUG ]] && echo " < closing binding from $BUFFER to $OUT_IP:$OUT_PT"; + rm $BUFFER 2>/dev/null && ( [[ $DEBUG ]] && echo " < $BUFFER deleted" ); + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; +} @@ -41,7 +50,7 @@ echo -n "" > $BUFFER; #--------------------------------------------------------# ( [[ $DEBUG ]] && 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 $NC_PID 2>/dev/null; on_exit;" HUP INT KILL TERM; outfail=0; @@ -72,17 +81,7 @@ echo -n "" > $BUFFER; LOOP_PID=$!; -# (2) Remove buffer + kill loop # -on_exit(){ - [[ $DEBUG ]] && echo " < closing binding from $BUFFER to $OUT_IP:$OUT_PT"; - rm $BUFFER 2>/dev/null && ( [[ $DEBUG ]] && echo " < $BUFFER deleted" ); - kill -INT $LOOP_PID 2>/dev/null; - - exit 1; -} trap "on_exit;" HUP INT KILL TERM; -wait $LOOP_PID; - -on_exit; \ No newline at end of file +echo -n "$LOOP_PID"; \ No newline at end of file