Rectify the get_host_ip implementation

In previous implementation of get_host_ip, global variable HOST_IP
is used to be a intermediate variable. In this case, if finally
failed to get HOST_IP, the original default value is also overwritten.
It's buggy.

Eg. in ssh case, when faied to get host ip, the default local host ip
"127.0.0.1" is lost too. that's not expected.

Change it by adding a local variable as intermediate variable.

Signed-off-by: Baoquan He <bhe@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Baoquan He 2013-02-01 15:40:26 +08:00
parent c64f56348c
commit 01bb9af7ed

View File

@ -125,15 +125,17 @@ is_raw_dump_target()
get_host_ip()
{
local _host
if is_nfs_dump_target || is_ssh_dump_target
then
kdumpnic=$(getarg kdumpnic=)
[ -z "$kdumpnic" ] && echo "failed to get kdumpnic!" && return 1
HOST_IP=`ip addr show dev $kdumpnic|grep 'inet '`
_host=`ip addr show dev $kdumpnic|grep 'inet '`
[ $? -ne 0 ] && echo "Wrong kdumpnic: $kdumpnic" && return 1
HOST_IP="${HOST_IP##*inet }"
HOST_IP="${HOST_IP%%/*}"
[ -z "$HOST_IP" ] && echo "Wrong kdumpnic: $kdumpnic" && return 1
_host="${_host##*inet }"
_host="${_host%%/*}"
[ -z "$_host" ] && echo "Wrong kdumpnic: $kdumpnic" && return 1
HOST_IP=$_host
fi
return 0
}