From 01bb9af7ed4aab6abc0ae3e18cbc2849f060306d Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Fri, 1 Feb 2013 15:40:26 +0800 Subject: [PATCH] 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 Acked-by: Dave Young --- dracut-kdump.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index d81ebc8..d46e728 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -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 }