#!/bin/sh

################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2005                 ##
##                                                                            ##
## This program is free software;  you can redistribute it and#or modify      ##
## it under the terms of the GNU General Public License as published by       ##
## the Free Software Foundation; either version 2 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program is distributed in the hope that it will be useful, but        ##
## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
## for more details.                                                          ##
##                                                                            ##
## You should have received a copy of the GNU General Public License          ##
## along with this program;  if not, write to the Free Software               ##
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
##                                                                            ##
##                                                                            ##
################################################################################
#
# File:
#   killall_icmp_traffic
#
# Description:
#   Kill all of the icmp traffic utilities (ping or ping6)
#
# Arguments:
#   None
#
# Returns:
#   None
#
# Author:
#   Mitsuru Chinen <mitch@jp.ibm.com>
#
# History:
#   Oct 19 2005 - Created (Mitsuru Chinen)
#
#-----------------------------------------------------------------------
#Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

# Make sure the value of LTPROOT
LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
export LTPROOT

# Check the environmanet variable for the test
. check_envval || exit 1

# Waiting time before outputting a warning message [sec]
WARN_WAIT=300


# Send SIGINT to ping and ping6
$LTP_RSH $RHOST "killall -SIGINT ping ping6" >/dev/null 2>&1

# Verify the all ping utitlities are dead.
start_epoc=`date +%s`
while true ; do
    #ret=`$LTP_RSH $RHOST 'ps auxw | fgrep -v grep | grep -l [[:blank:]]ping6*[[:blank:]] >/dev/null 2>&1 ; echo $?'`
    ret=`$LTP_RSH $RHOST 'ps auxw | fgrep -v grep | grep -l /ping6*[[:blank:]] >/dev/null 2>&1 ; echo $?'`

    if [ -z $ret ]; then
	continue
    fi

    if [ $ret -ne 0 ]; then
	break
    fi

    current_epoc=`date +%s`
    elapse_epoc=`expr $current_epoc - $start_epoc`
    if [ $elapse_epoc -ge $WARN_WAIT ]; then
	echo "ping command is not dead over $WARN_WAIT sec" >&2
    fi

    $LTP_RSH $RHOST "killall -SIGINT ping ping6" >/dev/null 2>&1
    sleep 1
done