UPD: bind-input/output now synchronous for the setup, then asynchronous (so the buffer file will always be ok)

This commit is contained in:
xdrm-brackets 2018-02-01 00:28:32 +01:00
parent 534b5a97ac
commit 73e388aff8
2 changed files with 23 additions and 26 deletions

View File

@ -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;
echo -n "$LOOP_PID";

View File

@ -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;
echo -n "$LOOP_PID";