1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) International Business Machines  Corp., 2005                 ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21##                                                                            ##
22################################################################################
23#
24# File:
25#   killall_udp_traffic
26#
27# Description:
28#   Kill all of the udp traffic utilities (ns-udpserver, ns-udpclient)
29#
30# Arguments:
31#   None
32#
33# Returns:
34#   None
35#
36# Author:
37#   Mitsuru Chinen <mitch@jp.ibm.com>
38#
39# History:
40#   Oct 19 2005 - Created (Mitsuru Chinen)
41#
42#-----------------------------------------------------------------------
43#Uncomment line below for debug output.
44#trace_logic=${trace_logic:-"set -x"}
45$trace_logic
46
47# Make sure the value of LTPROOT
48LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
49export LTPROOT
50
51# Check the environmanet variable for the test
52. check_envval || exit 1
53
54# Waiting time before outputting a warning message [sec]
55WARN_WAIT=300
56
57
58# Send SIGHUP both server and client
59killall -SIGHUP ns-udpserver >/dev/null 2>&1
60$LTP_RSH $RHOST "killall -SIGHUP ns-udpclient" >/dev/null 2>&1
61
62# Verify the server is dead.
63start_epoc=`date +%s`
64while true ; do
65    ps auxw | fgrep -v grep | fgrep -l ns-udpserver >/dev/null 2>&1
66    if [ $? -ne 0 ]; then
67	break
68    fi
69
70    current_epoc=`date +%s`
71    elapse_epoc=`expr $current_epoc - $start_epoc`
72    if [ $elapse_epoc -ge $WARN_WAIT ]; then
73	tst_resm TINFO "UDP traffic server is not dead over $WARN_WAIT sec" >&2
74    fi
75
76    killall -SIGHUP ns-udpserver >/dev/null 2>&1
77    sleep 1
78done
79
80# Verify the client is dead.
81start_epoc=`date +%s`
82while true ; do
83    #ret=`$LTP_RSH $RHOST 'ps auxw | fgrep -v grep | grep -l '[[:blank:]]ns-udpclient[[:blank:]]' >/dev/null 2>&1; echo $?'`
84    ret=`$LTP_RSH $RHOST 'ps auxw | fgrep -v grep | grep -l '/ns-udpclient[[:blank:]]' >/dev/null 2>&1; echo $?'`
85
86    if [ -z $ret ]; then
87	continue
88    fi
89
90    if [ $ret -ne 0 ]; then
91	break
92    fi
93
94    current_epoc=`date +%s`
95    elapse_epoc=`expr $current_epoc - $start_epoc`
96    if [ $elapse_epoc -ge $WARN_WAIT ]; then
97	tst_resm TINFO "UDP traffic client is not dead over $WARN_WAIT sec" >&2
98    fi
99    $LTP_RSH $RHOST "killall -SIGHUP ns-udpclient" >/dev/null 2>&1
100    sleep 1
101done
102