Skip to content

Commit

Permalink
added a trap for SIGINT to gracefully kill components upon CTRL+C
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasvw committed Apr 23, 2023
1 parent f9c78e2 commit 4764861
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions tsock_video
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@ puits=false
sourc=false
protocol="tcp"
port=`expr \`id -u\` % 3000 + 14578`
interrupted=1

usage() { echo "Usage: $0 [[-p|-s] [-t (tcp|mictcp)]" 1>&2; exit 1; }

# Stop all components gracefully
function graceful_stop ()
{

echo "Arret"
killall -9 cvlc > /dev/null 2>&1
killall -9 vlc > /dev/null 2>&1
killall -9 gateway > /dev/null 2>&1

if [ $interrupted -eq 1 ]; then
# Set return code to 2
exit 2
fi
}

# initialise trap to call graceful_stop function
# when signal 2 (SIGINT) is received
trap "graceful_stop" 2

while getopts "pst:" o; do
case "${o}" in
t)
Expand Down Expand Up @@ -55,9 +75,5 @@ fi

echo "Appuyez sur ENTREE pour arreter"
read line

echo "Arret"
killall -9 cvlc > /dev/null 2>&1
killall -9 vlc > /dev/null 2>&1
killall -9 gateway > /dev/null 2>&1

interrupted=0
graceful_stop

0 comments on commit 4764861

Please sign in to comment.