added a trap for SIGINT to gracefully kill components upon CTRL+C
This commit is contained in:
parent
f9c78e2d36
commit
476486195c
1 changed files with 22 additions and 6 deletions
28
tsock_video
28
tsock_video
|
@ -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)
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue