bash scripts: fix variable quoting issue

Fixed quoting issues found by shellcheck, no feature
change. This should fix many errors when there is space
in any shell variables, eg. dump target's name/path/id.

False positives are marked with "# shellcheck disable=SCXXXX", for
example, args are expected to split so it should not be quoted.

And replaced some `cut -d ' ' -fX` with `awk '{print $X}'` since cut
is fragile, and doesn't work well with any quoted strings that have
redundant space.

Following quoting related issues are fixed (check the link
for example code and what could go wrong):

https://github.com/koalaman/shellcheck/wiki/SC2046
https://github.com/koalaman/shellcheck/wiki/SC2053
https://github.com/koalaman/shellcheck/wiki/SC2068
https://github.com/koalaman/shellcheck/wiki/SC2086
https://github.com/koalaman/shellcheck/wiki/SC2206

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-09-08 17:21:41 +08:00
parent 70978c00e5
commit 86538ca6e2
4 changed files with 220 additions and 216 deletions

View File

@ -25,7 +25,7 @@ prepare_kernel_initrd() {
prepare_kdump_bootinfo prepare_kdump_bootinfo
# $kernel is a variable from dracut # $kernel is a variable from dracut
if [[ "$KDUMP_KERNELVER" != $kernel ]]; then if [[ "$KDUMP_KERNELVER" != "$kernel" ]]; then
dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \
"but the initramfs is generated for kernel version '$kernel'" "but the initramfs is generated for kernel version '$kernel'"
fi fi

View File

@ -53,7 +53,7 @@ depends() {
_dep="$_dep network" _dep="$_dep network"
fi fi
echo $_dep echo "$_dep"
} }
kdump_is_bridge() { kdump_is_bridge() {
@ -65,7 +65,7 @@ kdump_is_bond() {
} }
kdump_is_team() { kdump_is_team() {
[[ -f /usr/bin/teamnl ]] && teamnl $1 ports &> /dev/null [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null
} }
kdump_is_vlan() { kdump_is_vlan() {
@ -77,9 +77,9 @@ source_ifcfg_file() {
local ifcfg_file local ifcfg_file
dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager."
ifcfg_file=$(get_ifcfg_filename $1) ifcfg_file=$(get_ifcfg_filename "$1")
if [[ -f "${ifcfg_file}" ]]; then if [[ -f "${ifcfg_file}" ]]; then
. ${ifcfg_file} . "${ifcfg_file}"
else else
dwarning "The ifcfg file of $1 is not found!" dwarning "The ifcfg file of $1 is not found!"
fi fi
@ -93,7 +93,8 @@ kdump_setup_dns() {
local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
_tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS")
array=(${_tmp//|/ }) # shellcheck disable=SC2206
array=( ${_tmp//|/ } )
if [[ ${array[*]} ]]; then if [[ ${array[*]} ]]; then
for _dns in "${array[@]}" for _dns in "${array[@]}"
do do
@ -108,10 +109,10 @@ kdump_setup_dns() {
while read -r content; while read -r content;
do do
_nameserver=$(echo $content | grep ^nameserver) _nameserver=$(echo "$content" | grep ^nameserver)
[[ -z "$_nameserver" ]] && continue [[ -z "$_nameserver" ]] && continue
_dns=$(echo $_nameserver | cut -d' ' -f2) _dns=$(echo "$_nameserver" | awk '{print $2}')
[[ -z "$_dns" ]] && continue [[ -z "$_dns" ]] && continue
if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then
@ -237,14 +238,14 @@ kdump_static_ip() {
local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag
local _netmask _gateway _ipaddr _target _nexthop _prefix local _netmask _gateway _ipaddr _target _nexthop _prefix
_ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") _ipaddr=$(ip addr show dev "$_netdev" permanent | awk "/ $_srcaddr\/.* /{print \$2}")
if is_ipv6_address $_srcaddr; then if is_ipv6_address "$_srcaddr"; then
_ipv6_flag="-6" _ipv6_flag="-6"
fi fi
if [[ -n "$_ipaddr" ]]; then if [[ -n "$_ipaddr" ]]; then
_gateway=$(ip $_ipv6_flag route list dev $_netdev | \ _gateway=$(ip $_ipv6_flag route list dev "$_netdev" | \
awk '/^default /{print $3}' | head -n 1) awk '/^default /{print $3}' | head -n 1)
if [[ "x" != "x"$_ipv6_flag ]]; then if [[ "x" != "x"$_ipv6_flag ]]; then
@ -266,23 +267,23 @@ kdump_static_ip() {
/sbin/ip $_ipv6_flag route show | grep -v default |\ /sbin/ip $_ipv6_flag route show | grep -v default |\
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
while read -r _route; do while read -r _route; do
_target=$(echo $_route | cut -d ' ' -f1) _target=$(echo "$_route" | awk '{print $1}')
_nexthop=$(echo $_route | cut -d ' ' -f3) _nexthop=$(echo "$_route" | awk '{print $3}')
if [[ "x" != "x"$_ipv6_flag ]]; then if [[ "x" != "x"$_ipv6_flag ]]; then
_target="[$_target]" _target="[$_target]"
_nexthop="[$_nexthop]" _nexthop="[$_nexthop]"
fi fi
echo "rd.route=$_target:$_nexthop:$kdumpnic" echo "rd.route=$_target:$_nexthop:$kdumpnic"
done >> ${initdir}/etc/cmdline.d/45route-static.conf done >> "${initdir}/etc/cmdline.d/45route-static.conf"
kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic kdump_handle_mulitpath_route "$_netdev" "$_srcaddr" "$kdumpnic"
} }
kdump_handle_mulitpath_route() { kdump_handle_mulitpath_route() {
local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag
local _target _nexthop _route _weight _max_weight _rule local _target _nexthop _route _weight _max_weight _rule
if is_ipv6_address $_srcaddr; then if is_ipv6_address "$_srcaddr"; then
_ipv6_flag="-6" _ipv6_flag="-6"
fi fi
@ -308,20 +309,20 @@ kdump_handle_mulitpath_route() {
_target=$(echo "$_route" | cut -d ' ' -f1) _target=$(echo "$_route" | cut -d ' ' -f1)
_rule="" _max_weight=0 _weight=0 _rule="" _max_weight=0 _weight=0
fi fi
done >> ${initdir}/etc/cmdline.d/45route-static.conf\ done >> "${initdir}/etc/cmdline.d/45route-static.conf"\
<<< "$(/sbin/ip $_ipv6_flag route show)" <<< "$(/sbin/ip $_ipv6_flag route show)"
[[ -n $_rule ]] && echo $_rule >> ${initdir}/etc/cmdline.d/45route-static.conf [[ -n $_rule ]] && echo "$_rule" >> "${initdir}/etc/cmdline.d/45route-static.conf"
} }
kdump_get_mac_addr() { kdump_get_mac_addr() {
cat /sys/class/net/$1/address cat "/sys/class/net/$1/address"
} }
#Bonding or team master modifies the mac address #Bonding or team master modifies the mac address
#of its slaves, we should use perm address #of its slaves, we should use perm address
kdump_get_perm_addr() { kdump_get_perm_addr() {
local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //') local addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //')
if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]]
then then
derror "Can't get the permanent address of $1" derror "Can't get the permanent address of $1"
@ -367,9 +368,9 @@ kdump_setup_bridge() {
elif kdump_is_vlan "$_dev"; then elif kdump_is_vlan "$_dev"; then
kdump_setup_vlan "$_dev" kdump_setup_vlan "$_dev"
else else
_mac=$(kdump_get_mac_addr $_dev) _mac=$(kdump_get_mac_addr "$_dev")
_kdumpdev=$(kdump_setup_ifname $_dev) _kdumpdev=$(kdump_setup_ifname "$_dev")
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/41bridge.conf"
fi fi
_brif+="$_kdumpdev," _brif+="$_kdumpdev,"
done done
@ -383,10 +384,10 @@ kdump_setup_bond() {
local _netdev="$1" local _netdev="$1"
local _nm_show_cmd="$2" local _nm_show_cmd="$2"
local _dev _mac _slaves _kdumpdev _bondoptions local _dev _mac _slaves _kdumpdev _bondoptions
for _dev in $(cat /sys/class/net/$_netdev/bonding/slaves); do for _dev in $(cat "/sys/class/net/$_netdev/bonding/slaves"); do
_mac=$(kdump_get_perm_addr $_dev) _mac=$(kdump_get_perm_addr "$_dev")
_kdumpdev=$(kdump_setup_ifname $_dev) _kdumpdev=$(kdump_setup_ifname "$_dev")
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/42bond.conf"
_slaves+="$_kdumpdev," _slaves+="$_kdumpdev,"
done done
echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf" echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf"
@ -395,8 +396,8 @@ kdump_setup_bond() {
if [[ -z "$_bondoptions" ]]; then if [[ -z "$_bondoptions" ]]; then
dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file $_netdev source_ifcfg_file "$_netdev"
_bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")" _bondoptions="$(echo "$BONDING_OPTS" | xargs echo | tr " " ",")"
fi fi
if [[ -z "$_bondoptions" ]]; then if [[ -z "$_bondoptions" ]]; then
@ -404,36 +405,36 @@ kdump_setup_bond() {
exit 1 exit 1
fi fi
echo ":$_bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf echo ":$_bondoptions" >> "${initdir}/etc/cmdline.d/42bond.conf"
} }
kdump_setup_team() { kdump_setup_team() {
local _netdev=$1 local _netdev=$1
local _dev _mac _slaves _kdumpdev local _dev _mac _slaves _kdumpdev
for _dev in $(teamnl $_netdev ports | awk -F':' '{print $2}'); do for _dev in $(teamnl "$_netdev" ports | awk -F':' '{print $2}'); do
_mac=$(kdump_get_perm_addr $_dev) _mac=$(kdump_get_perm_addr "$_dev")
_kdumpdev=$(kdump_setup_ifname $_dev) _kdumpdev=$(kdump_setup_ifname "$_dev")
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/44team.conf"
_slaves+="$_kdumpdev," _slaves+="$_kdumpdev,"
done done
echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf"
#Buggy version teamdctl outputs to stderr! #Buggy version teamdctl outputs to stderr!
#Try to use the latest version of teamd. #Try to use the latest version of teamd.
teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf"
if [[ $? -ne 0 ]] if [[ $? -ne 0 ]]
then then
derror "teamdctl failed." derror "teamdctl failed."
exit 1 exit 1
fi fi
inst_dir /etc/teamd inst_dir /etc/teamd
inst_simple ${initdir}/tmp/$$-$_netdev.conf "/etc/teamd/$_netdev.conf" inst_simple "${initdir}/tmp/$$-$_netdev.conf" "/etc/teamd/$_netdev.conf"
rm -f ${initdir}/tmp/$$-$_netdev.conf rm -f "${initdir}/tmp/$$-$_netdev.conf"
} }
kdump_setup_vlan() { kdump_setup_vlan() {
local _netdev=$1 local _netdev=$1
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
local _netmac="$(kdump_get_mac_addr $_phydev)" local _netmac="$(kdump_get_mac_addr "$_phydev")"
local _kdumpdev local _kdumpdev
#Just support vlan over bond and team #Just support vlan over bond and team
@ -445,10 +446,10 @@ kdump_setup_vlan() {
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
exit 1 exit 1
fi fi
echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf"
else else
_kdumpdev="$(kdump_setup_ifname $_phydev)" _kdumpdev="$(kdump_setup_ifname "$_phydev")"
echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf echo " vlan=$(kdump_setup_ifname "$_netdev"):$_kdumpdev ifname=$_kdumpdev:$_netmac" > "${initdir}/etc/cmdline.d/43vlan.conf"
fi fi
} }
@ -465,7 +466,7 @@ find_online_znet_device() {
for d in $NETWORK_DEVICES for d in $NETWORK_DEVICES
do do
[[ ! -f "$d/online" ]] && continue [[ ! -f "$d/online" ]] && continue
read -r ONLINE < $d/online read -r ONLINE < "$d/online"
if [[ $ONLINE -ne 1 ]]; then if [[ $ONLINE -ne 1 ]]; then
continue continue
fi fi
@ -473,10 +474,10 @@ find_online_znet_device() {
# device is online) # device is online)
if [[ -f $d/if_name ]] if [[ -f $d/if_name ]]
then then
read -r ifname < $d/if_name read -r ifname < "$d/if_name"
elif [[ -d $d/net ]] elif [[ -d $d/net ]]
then then
ifname=$(ls $d/net/) ifname=$(ls "$d/net/")
fi fi
[[ -n "$ifname" ]] && break [[ -n "$ifname" ]] && break
done done
@ -500,7 +501,7 @@ kdump_setup_znet() {
if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file $_netdev source_ifcfg_file "$_netdev"
for i in $OPTIONS; do for i in $OPTIONS; do
_options=${_options},$i _options=${_options},$i
done done
@ -510,17 +511,17 @@ kdump_setup_znet() {
exit 1 exit 1
fi fi
echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf"
} }
kdump_get_ip_route() kdump_get_ip_route()
{ {
local _route=$(/sbin/ip -o route get to $1 2>&1) local _route=$(/sbin/ip -o route get to "$1" 2>&1)
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
derror "Bad kdump network destination: $1" derror "Bad kdump network destination: $1"
exit 1 exit 1
fi fi
echo $_route echo "$_route"
} }
kdump_get_ip_route_field() kdump_get_ip_route_field()
@ -530,15 +531,15 @@ kdump_get_ip_route_field()
kdump_get_remote_ip() kdump_get_remote_ip()
{ {
local _remote=$(get_remote_host $1) _remote_temp local _remote=$(get_remote_host "$1") _remote_temp
if is_hostname $_remote; then if is_hostname "$_remote"; then
_remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1) _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1)
if [[ -z "$_remote_temp" ]]; then if [[ -z "$_remote_temp" ]]; then
_remote_temp=$(getent ahosts $_remote | head -n 1) _remote_temp=$(getent ahosts "$_remote" | head -n 1)
fi fi
_remote=$(echo $_remote_temp | cut -d' ' -f1) _remote=$(echo "$_remote_temp" | awk '{print $1}')
fi fi
echo $_remote echo "$_remote"
} }
# Setup dracut to bring up network interface that enable # Setup dracut to bring up network interface that enable
@ -549,13 +550,13 @@ kdump_install_net() {
local _static _proto _ip_conf _ip_opts _ifname_opts local _static _proto _ip_conf _ip_opts _ifname_opts
local _znet_netdev _nm_show_cmd_znet local _znet_netdev _nm_show_cmd_znet
_destaddr=$(kdump_get_remote_ip $1) _destaddr=$(kdump_get_remote_ip "$1")
_route=$(kdump_get_ip_route $_destaddr) _route=$(kdump_get_ip_route "$_destaddr")
_srcaddr=$(kdump_get_ip_route_field "$_route" "src") _srcaddr=$(kdump_get_ip_route_field "$_route" "src")
_netdev=$(kdump_get_ip_route_field "$_route" "dev") _netdev=$(kdump_get_ip_route_field "$_route" "dev")
_nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") _nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev")
_netmac=$(kdump_get_mac_addr $_netdev) _netmac=$(kdump_get_mac_addr "$_netdev")
kdumpnic=$(kdump_setup_ifname $_netdev) kdumpnic=$(kdump_setup_ifname "$_netdev")
_znet_netdev=$(find_online_znet_device) _znet_netdev=$(find_online_znet_device)
if [[ -n "$_znet_netdev" ]]; then if [[ -n "$_znet_netdev" ]]; then
@ -567,10 +568,10 @@ kdump_install_net() {
fi fi
fi fi
_static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) _static=$(kdump_static_ip "$_netdev" "$_srcaddr" "$kdumpnic")
if [[ -n "$_static" ]]; then if [[ -n "$_static" ]]; then
_proto=none _proto=none
elif is_ipv6_address $_srcaddr; then elif is_ipv6_address "$_srcaddr"; then
_proto=auto6 _proto=auto6
else else
_proto=dhcp _proto=dhcp
@ -583,9 +584,9 @@ kdump_install_net() {
# so we have to avoid adding duplicates # so we have to avoid adding duplicates
# We should also check /proc/cmdline for existing ip=xx arg. # We should also check /proc/cmdline for existing ip=xx arg.
# For example, iscsi boot will specify ip=xxx arg in cmdline. # For example, iscsi boot will specify ip=xxx arg in cmdline.
if [[ ! -f $_ip_conf ]] || ! grep -q $_ip_opts $_ip_conf &&\ if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" &&\
! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then
echo "$_ip_opts" >> $_ip_conf echo "$_ip_opts" >> "$_ip_conf"
fi fi
if kdump_is_bridge "$_netdev"; then if kdump_is_bridge "$_netdev"; then
@ -601,14 +602,14 @@ kdump_install_net() {
kdump_setup_vlan "$_netdev" kdump_setup_vlan "$_netdev"
else else
_ifname_opts=" ifname=$kdumpnic:$_netmac" _ifname_opts=" ifname=$kdumpnic:$_netmac"
echo "$_ifname_opts" >> $_ip_conf echo "$_ifname_opts" >> "$_ip_conf"
fi fi
kdump_setup_dns "$_netdev" "$_nm_show_cmd" kdump_setup_dns "$_netdev" "$_nm_show_cmd"
if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then
# network-manager module needs this parameter # network-manager module needs this parameter
echo "rd.neednet" >> ${initdir}/etc/cmdline.d/50neednet.conf echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf"
fi fi
# Save netdev used for kdump as cmdline # Save netdev used for kdump as cmdline
@ -620,8 +621,8 @@ kdump_install_net() {
# gateway. # gateway.
if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] && if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] &&
[[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then
echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf"
echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf echo "bootdev=$kdumpnic" > "${initdir}/etc/cmdline.d/70bootdev.conf"
fi fi
} }
@ -630,7 +631,7 @@ kdump_install_pre_post_conf() {
if [[ -d /etc/kdump/pre.d ]]; then if [[ -d /etc/kdump/pre.d ]]; then
for file in /etc/kdump/pre.d/*; do for file in /etc/kdump/pre.d/*; do
if [[ -x "$file" ]]; then if [[ -x "$file" ]]; then
dracut_install $file dracut_install "$file"
elif [[ $file != "/etc/kdump/pre.d/*" ]]; then elif [[ $file != "/etc/kdump/pre.d/*" ]]; then
echo "$file is not executable" echo "$file is not executable"
fi fi
@ -640,7 +641,7 @@ kdump_install_pre_post_conf() {
if [[ -d /etc/kdump/post.d ]]; then if [[ -d /etc/kdump/post.d ]]; then
for file in /etc/kdump/post.d/*; do for file in /etc/kdump/post.d/*; do
if [[ -x "$file" ]]; then if [[ -x "$file" ]]; then
dracut_install $file dracut_install "$file"
elif [[ $file != "/etc/kdump/post.d/*" ]]; then elif [[ $file != "/etc/kdump/post.d/*" ]]; then
echo "$file is not executable" echo "$file is not executable"
fi fi
@ -655,19 +656,19 @@ default_dump_target_install_conf()
is_user_configured_dump_target && return is_user_configured_dump_target && return
_save_path=$(get_bind_mount_source $(get_save_path)) _save_path=$(get_bind_mount_source "$(get_save_path)")
_target=$(get_target_from_path $_save_path) _target=$(get_target_from_path "$_save_path")
_mntpoint=$(get_mntpoint_from_target $_target) _mntpoint=$(get_mntpoint_from_target "$_target")
_fstype=$(get_fs_type_from_target $_target) _fstype=$(get_fs_type_from_target "$_target")
if is_fs_type_nfs $_fstype; then if is_fs_type_nfs "$_fstype"; then
kdump_install_net "$_target" kdump_install_net "$_target"
_fstype="nfs" _fstype="nfs"
else else
_target=$(kdump_get_persistent_dev $_target) _target=$(kdump_get_persistent_dev "$_target")
fi fi
echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf echo "$_fstype $_target" >> "${initdir}/tmp/$$-kdump.conf"
# don't touch the path under root mount # don't touch the path under root mount
if [[ "$_mntpoint" != "/" ]]; then if [[ "$_mntpoint" != "/" ]]; then
@ -675,8 +676,8 @@ default_dump_target_install_conf()
fi fi
#erase the old path line, then insert the parsed path #erase the old path line, then insert the parsed path
sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf sed -i "/^path/d" "${initdir}/tmp/$$-kdump.conf"
echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf echo "path $_save_path" >> "${initdir}/tmp/$$-kdump.conf"
} }
#install kdump.conf and what user specifies in kdump.conf #install kdump.conf and what user specifies in kdump.conf
@ -690,12 +691,12 @@ kdump_install_conf() {
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
case "$_opt" in case "$_opt" in
raw) raw)
_pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val) _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;; ;;
ext[234]|xfs|btrfs|minix) ext[234]|xfs|btrfs|minix)
_pdev=$(kdump_get_persistent_dev $_val) _pdev=$(kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;; ;;
ssh|nfs) ssh|nfs)
kdump_install_net "$_val" kdump_install_net "$_val"
@ -706,7 +707,7 @@ kdump_install_conf() {
fi fi
;; ;;
kdump_pre|kdump_post|extra_bins) kdump_pre|kdump_post|extra_bins)
dracut_install $_val dracut_install "$_val"
;; ;;
core_collector) core_collector)
dracut_install "${_val%%[[:blank:]]*}" dracut_install "${_val%%[[:blank:]]*}"
@ -720,7 +721,7 @@ kdump_install_conf() {
kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf"
inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf" inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf"
rm -f ${initdir}/tmp/$$-kdump.conf rm -f "${initdir}/tmp/$$-kdump.conf"
} }
# Default sysctl parameters should suffice for kdump kernel. # Default sysctl parameters should suffice for kdump kernel.
@ -742,9 +743,9 @@ kdump_iscsi_get_rec_val() {
# The open-iscsi 742 release changed to using flat files in # The open-iscsi 742 release changed to using flat files in
# /var/lib/iscsi. # /var/lib/iscsi.
result=$(/sbin/iscsiadm --show -m session -r ${1} | grep "^${2} = ") result=$(/sbin/iscsiadm --show -m session -r "$1" | grep "^${2} = ")
result=${result##* = } result=${result##* = }
echo $result echo "$result"
} }
kdump_get_iscsi_initiator() { kdump_get_iscsi_initiator() {
@ -770,7 +771,7 @@ kdump_get_iscsi_initiator() {
# Figure out iBFT session according to session type # Figure out iBFT session according to session type
is_ibft() { is_ibft() {
[[ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ]] [[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" = fw ]]
} }
kdump_setup_iscsi_device() { kdump_setup_iscsi_device() {
@ -786,32 +787,32 @@ kdump_setup_iscsi_device() {
# Check once before getting explicit values, so we can bail out early, # Check once before getting explicit values, so we can bail out early,
# e.g. in case of pure-hardware(all-offload) iscsi. # e.g. in case of pure-hardware(all-offload) iscsi.
if ! /sbin/iscsiadm -m session -r ${path} &>/dev/null ; then if ! /sbin/iscsiadm -m session -r "$path" &>/dev/null ; then
return 1 return 1
fi fi
if is_ibft ${path}; then if is_ibft "$path"; then
return return
fi fi
# Remove software iscsi cmdline generated by 95iscsi, # Remove software iscsi cmdline generated by 95iscsi,
# and let kdump regenerate here. # and let kdump regenerate here.
rm -f ${initdir}/etc/cmdline.d/95iscsi.conf rm -f "${initdir}/etc/cmdline.d/95iscsi.conf"
tgt_name=$(kdump_iscsi_get_rec_val ${path} "node.name") tgt_name=$(kdump_iscsi_get_rec_val "$path" "node.name")
tgt_ipaddr=$(kdump_iscsi_get_rec_val ${path} "node.conn\[0\].address") tgt_ipaddr=$(kdump_iscsi_get_rec_val "$path" "node.conn\[0\].address")
# get and set username and password details # get and set username and password details
username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username") username=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username")
[[ "$username" == "<empty>" ]] && username="" [[ "$username" == "<empty>" ]] && username=""
password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password") password=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password")
[[ "$password" == "<empty>" ]] && password="" [[ "$password" == "<empty>" ]] && password=""
username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in") username_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username_in")
[[ -n "$username" ]] && userpwd_str="$username:$password" [[ -n "$username" ]] && userpwd_str="$username:$password"
# get and set incoming username and password details # get and set incoming username and password details
[[ "$username_in" == "<empty>" ]] && username_in="" [[ "$username_in" == "<empty>" ]] && username_in=""
password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in") password_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password_in")
[[ "$password_in" == "<empty>" ]] && password_in="" [[ "$password_in" == "<empty>" ]] && password_in=""
[[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in" [[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in"
@ -822,16 +823,16 @@ kdump_setup_iscsi_device() {
# FIXME: Do we need to parse and set other parameters like protocol, port # FIXME: Do we need to parse and set other parameters like protocol, port
# iscsi_iface_name, netdev_name, LUN etc. # iscsi_iface_name, netdev_name, LUN etc.
if is_ipv6_address $tgt_ipaddr; then if is_ipv6_address "$tgt_ipaddr"; then
tgt_ipaddr="[$tgt_ipaddr]" tgt_ipaddr="[$tgt_ipaddr]"
fi fi
netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name" netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name"
[[ -f $netroot_conf ]] || touch $netroot_conf [[ -f $netroot_conf ]] || touch "$netroot_conf"
# If netroot target does not exist already, append. # If netroot target does not exist already, append.
if ! grep -q $netroot_str $netroot_conf; then if ! grep -q "$netroot_str" "$netroot_conf"; then
echo $netroot_str >> $netroot_conf echo "$netroot_str" >> "$netroot_conf"
dinfo "Appended $netroot_str to $netroot_conf" dinfo "Appended $netroot_str to $netroot_conf"
fi fi
@ -840,9 +841,9 @@ kdump_setup_iscsi_device() {
[[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 [[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1
# If initiator details do not exist already, append. # If initiator details do not exist already, append.
if ! grep -q "$initiator_str" $netroot_conf; then if ! grep -q "$initiator_str" "$netroot_conf"; then
echo "$initiator_str" >> $netroot_conf echo "$initiator_str" >> "$netroot_conf"
dinfo "Appended "$initiator_str" to $netroot_conf" dinfo "Appended $initiator_str to $netroot_conf"
fi fi
} }
@ -877,13 +878,13 @@ get_alias() {
for ip in $ips for ip in $ips
do do
# in /etc/hosts, alias can come at the 2nd column # in /etc/hosts, alias can come at the 2nd column
entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }')
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
alias_set="$alias_set $entries" alias_set="$alias_set $entries"
fi fi
done done
echo $alias_set echo "$alias_set"
} }
is_localhost() { is_localhost() {
@ -914,23 +915,23 @@ get_pcs_fence_kdump_nodes() {
# we need to convert each to node1, node2 ... nodeX in each iteration # we need to convert each to node1, node2 ... nodeX in each iteration
for node in ${nodelist}; do for node in ${nodelist}; do
# convert $node from 'uname="nodeX"' to 'nodeX' # convert $node from 'uname="nodeX"' to 'nodeX'
eval $node eval "$node"
nodename=$uname nodename="$uname"
# Skip its own node name # Skip its own node name
if is_localhost $nodename; then if is_localhost "$nodename"; then
continue continue
fi fi
nodes="$nodes $nodename" nodes="$nodes $nodename"
done done
echo $nodes echo "$nodes"
} }
# retrieves fence_kdump args from config file # retrieves fence_kdump args from config file
get_pcs_fence_kdump_args() { get_pcs_fence_kdump_args() {
if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then
. $FENCE_KDUMP_CONFIG_FILE . "$FENCE_KDUMP_CONFIG_FILE"
echo $FENCE_KDUMP_OPTS echo "$FENCE_KDUMP_OPTS"
fi fi
} }
@ -941,12 +942,12 @@ get_generic_fence_kdump_nodes() {
nodes=$(kdump_get_conf_val "fence_kdump_nodes") nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in ${nodes}; do for node in ${nodes}; do
# Skip its own node name # Skip its own node name
if is_localhost $node; then if is_localhost "$node"; then
continue continue
fi fi
filtered="$filtered $node" filtered="$filtered $node"
done done
echo $filtered echo "$filtered"
} }
# setup fence_kdump in cluster # setup fence_kdump in cluster
@ -963,11 +964,11 @@ kdump_configure_fence_kdump () {
nodes=$(get_pcs_fence_kdump_nodes) nodes=$(get_pcs_fence_kdump_nodes)
# set appropriate options in kdump.conf # set appropriate options in kdump.conf
echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file} echo "fence_kdump_nodes $nodes" >> "${kdump_cfg_file}"
args=$(get_pcs_fence_kdump_args) args=$(get_pcs_fence_kdump_args)
if [[ -n "$args" ]]; then if [[ -n "$args" ]]; then
echo "fence_kdump_args $args" >> ${kdump_cfg_file} echo "fence_kdump_args $args" >> "${kdump_cfg_file}"
fi fi
else else
@ -977,12 +978,12 @@ kdump_configure_fence_kdump () {
# setup network for each node # setup network for each node
for node in ${nodes}; do for node in ${nodes}; do
kdump_install_net $node kdump_install_net "$node"
done done
dracut_install /etc/hosts dracut_install /etc/hosts
dracut_install /etc/nsswitch.conf dracut_install /etc/nsswitch.conf
dracut_install $FENCE_KDUMP_SEND dracut_install "$FENCE_KDUMP_SEND"
} }
# Install a random seed used to feed /dev/urandom # Install a random seed used to feed /dev/urandom
@ -992,32 +993,32 @@ kdump_install_random_seed() {
poolsize=$(</proc/sys/kernel/random/poolsize) poolsize=$(</proc/sys/kernel/random/poolsize)
if [[ ! -d ${initdir}/var/lib/ ]]; then if [[ ! -d "${initdir}/var/lib/" ]]; then
mkdir -p ${initdir}/var/lib/ mkdir -p "${initdir}/var/lib/"
fi fi
dd if=/dev/urandom of=${initdir}/var/lib/random-seed \ dd if=/dev/urandom of="${initdir}/var/lib/random-seed" \
bs=$poolsize count=1 2> /dev/null bs="$poolsize" count=1 2> /dev/null
} }
kdump_install_systemd_conf() { kdump_install_systemd_conf() {
# Kdump turns out to require longer default systemd mount timeout # Kdump turns out to require longer default systemd mount timeout
# than 1st kernel(90s by default), we use default 300s for kdump. # than 1st kernel(90s by default), we use default 300s for kdump.
grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null grep -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"* &>/dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
mkdir -p ${initdir}/etc/systemd/system.conf.d mkdir -p "${initdir}/etc/systemd/system.conf.d"
echo "[Manager]" > ${initdir}/etc/systemd/system.conf.d/kdump.conf echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf"
echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf"
fi fi
# Forward logs to console directly, and don't read Kmsg, this avoids # Forward logs to console directly, and don't read Kmsg, this avoids
# unneccessary memory consumption and make console output more useful. # unneccessary memory consumption and make console output more useful.
# Only do so for non fadump image. # Only do so for non fadump image.
mkdir -p ${initdir}/etc/systemd/journald.conf.d mkdir -p "${initdir}/etc/systemd/journald.conf.d"
echo "[Journal]" > ${initdir}/etc/systemd/journald.conf.d/kdump.conf echo "[Journal]" > "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "Storage=volatile" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf echo "Storage=volatile" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "ReadKMsg=no" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf echo "ReadKMsg=no" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
echo "ForwardToConsole=yes" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf echo "ForwardToConsole=yes" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf"
} }
install() { install() {
@ -1030,7 +1031,7 @@ install() {
fi fi
dracut_install -o /etc/adjtime /etc/localtime dracut_install -o /etc/adjtime /etc/localtime
inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress"
chmod +x ${initdir}/kdumpscripts/monitor_dd_progress chmod +x "${initdir}/kdumpscripts/monitor_dd_progress"
inst "/bin/dd" "/bin/dd" inst "/bin/dd" "/bin/dd"
inst "/bin/tail" "/bin/tail" inst "/bin/tail" "/bin/tail"
inst "/bin/date" "/bin/date" inst "/bin/date" "/bin/date"
@ -1076,7 +1077,7 @@ install() {
# actually does nothing. # actually does nothing.
sed -i -e \ sed -i -e \
's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \
${initdir}/etc/lvm/lvm.conf &>/dev/null "${initdir}/etc/lvm/lvm.conf" &>/dev/null
# Save more memory by dropping switch root capability # Save more memory by dropping switch root capability
dracut_no_switch_root dracut_no_switch_root

104
kdumpctl
View File

@ -78,11 +78,11 @@ save_core()
{ {
coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
mkdir -p $coredir mkdir -p "$coredir"
ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete"
cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete"
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
mv $coredir/vmcore-incomplete $coredir/vmcore mv "$coredir/vmcore-incomplete" "$coredir/vmcore"
dinfo "saved a vmcore to $coredir" dinfo "saved a vmcore to $coredir"
else else
derror "failed to save a vmcore to $coredir" derror "failed to save a vmcore to $coredir"
@ -93,9 +93,9 @@ save_core()
# https://fedorahosted.org/abrt/ # https://fedorahosted.org/abrt/
if [[ -x /usr/bin/dumpoops ]]; then if [[ -x /usr/bin/dumpoops ]]; then
ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg"
makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg >/dev/null 2>&1 makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1
ddebug "dumpoops -d $coredir/dmesg" ddebug "dumpoops -d $coredir/dmesg"
dumpoops -d $coredir/dmesg >/dev/null 2>&1 dumpoops -d "$coredir/dmesg" >/dev/null 2>&1
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
dinfo "kernel oops has been collected by abrt tool" dinfo "kernel oops has been collected by abrt tool"
fi fi
@ -121,7 +121,7 @@ check_earlykdump_is_enabled()
rebuild_kdump_initrd() rebuild_kdump_initrd()
{ {
ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER"
$MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER $MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER"
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
derror "mkdumprd: failed to make kdump initrd" derror "mkdumprd: failed to make kdump initrd"
return 1 return 1
@ -136,8 +136,8 @@ rebuild_kdump_initrd()
rebuild_initrd() rebuild_initrd()
{ {
if [[ ! -w $(dirname $TARGET_INITRD) ]];then if [[ ! -w $(dirname "$TARGET_INITRD") ]];then
derror "$(dirname $TARGET_INITRD) does not have write permission. Cannot rebuild $TARGET_INITRD" derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD"
return 1 return 1
fi fi
@ -183,11 +183,11 @@ backup_default_initrd()
if [[ ! -e $DEFAULT_INITRD_BAK ]]; then if [[ ! -e $DEFAULT_INITRD_BAK ]]; then
dinfo "Backing up $DEFAULT_INITRD before rebuild." dinfo "Backing up $DEFAULT_INITRD before rebuild."
# save checksum to verify before restoring # save checksum to verify before restoring
sha1sum $DEFAULT_INITRD > $INITRD_CHECKSUM_LOCATION sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION"
cp $DEFAULT_INITRD $DEFAULT_INITRD_BAK cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK"
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
dwarn "WARNING: failed to backup $DEFAULT_INITRD." dwarn "WARNING: failed to backup $DEFAULT_INITRD."
rm -f $DEFAULT_INITRD_BAK rm -f "$DEFAULT_INITRD_BAK"
fi fi
fi fi
} }
@ -210,7 +210,7 @@ restore_default_initrd()
dwarn "WARNING: checksum mismatch! Can't restore original initrd.." dwarn "WARNING: checksum mismatch! Can't restore original initrd.."
else else
rm -f $INITRD_CHECKSUM_LOCATION rm -f $INITRD_CHECKSUM_LOCATION
mv $DEFAULT_INITRD_BAK $DEFAULT_INITRD mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
derror "Restoring original initrd as fadump mode is disabled." derror "Restoring original initrd as fadump mode is disabled."
sync sync
@ -226,7 +226,7 @@ check_config()
case "$config_opt" in case "$config_opt" in
dracut_args) dracut_args)
if [[ $config_val == *--mount* ]]; then if [[ $config_val == *--mount* ]]; then
if [[ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then
derror "Multiple mount targets specified in one \"dracut_args\"." derror "Multiple mount targets specified in one \"dracut_args\"."
return 1 return 1
fi fi
@ -297,13 +297,13 @@ get_pcs_cluster_modified_files()
fi fi
if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then
time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE) time_stamp=$(stat -c "%Y" "$FENCE_KDUMP_CONFIG_FILE")
if [[ "$time_stamp" -gt "$image_time" ]]; then if [[ "$time_stamp" -gt "$image_time" ]]; then
modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE"
fi fi
fi fi
echo $modified_files echo "$modified_files"
} }
setup_initrd() setup_initrd()
@ -314,7 +314,7 @@ setup_initrd()
return 1 return 1
fi fi
DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename $DEFAULT_INITRD).default" DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename "$DEFAULT_INITRD").default"
if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
TARGET_INITRD="$DEFAULT_INITRD" TARGET_INITRD="$DEFAULT_INITRD"
@ -357,7 +357,7 @@ check_files_modified()
fi fi
HOOKS="$HOOKS $POST_FILES $PRE_FILES" HOOKS="$HOOKS $POST_FILES $PRE_FILES"
CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}')
CORE_COLLECTOR=$(type -P $CORE_COLLECTOR) CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR")
# POST_FILES and PRE_FILES are already checked against executable, need not to check again. # POST_FILES and PRE_FILES are already checked against executable, need not to check again.
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
CHECK_FILES=$(kdump_get_conf_val extra_bins) CHECK_FILES=$(kdump_get_conf_val extra_bins)
@ -375,8 +375,8 @@ check_files_modified()
_module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)" _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
files="$files $_module_file" files="$files $_module_file"
for _dep_modules in $(modinfo -F depends $_module | tr ',' ' '); do for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do
files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename $_dep_modules 2>/dev/null)" files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)"
done done
else else
# If it's not a module nor builtin, give an error # If it's not a module nor builtin, give an error
@ -394,13 +394,13 @@ check_files_modified()
for file in $files; do for file in $files; do
if [[ -e "$file" ]]; then if [[ -e "$file" ]]; then
time_stamp=$(stat -c "%Y" $file) time_stamp=$(stat -c "%Y" "$file")
if [[ "$time_stamp" -gt "$image_time" ]]; then if [[ "$time_stamp" -gt "$image_time" ]]; then
modified_files="$modified_files $file" modified_files="$modified_files $file"
fi fi
if [[ -L "$file" ]]; then if [[ -L "$file" ]]; then
file=$(readlink -m $file) file=$(readlink -m "$file")
time_stamp=$(stat -c "%Y" $file) time_stamp=$(stat -c "%Y" "$file")
if [[ "$time_stamp" -gt "$image_time" ]]; then if [[ "$time_stamp" -gt "$image_time" ]]; then
modified_files="$modified_files $file" modified_files="$modified_files $file"
fi fi
@ -453,8 +453,8 @@ check_drivers_modified()
ddebug "Modules included in old initramfs: '$_old_drivers'" ddebug "Modules included in old initramfs: '$_old_drivers'"
for _driver in $_new_drivers; do for _driver in $_new_drivers; do
# Skip deprecated/invalid driver name or built-in module # Skip deprecated/invalid driver name or built-in module
_module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name $_driver 2>/dev/null) _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null)
_module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n $_driver 2>/dev/null) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null)
if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then
continue continue
fi fi
@ -483,21 +483,21 @@ check_fs_modified()
fi fi
_target=$(get_block_dump_target) _target=$(get_block_dump_target)
_new_fstype=$(get_fs_type_from_target $_target) _new_fstype=$(get_fs_type_from_target "$_target")
if [[ -z "$_target" ]] || [[ -z "$_new_fstype" ]];then if [[ -z "$_target" ]] || [[ -z "$_new_fstype" ]];then
derror "Dump target is invalid" derror "Dump target is invalid"
return 2 return 2
fi fi
ddebug "_target=$_target _new_fstype=$_new_fstype" ddebug "_target=$_target _new_fstype=$_new_fstype"
_new_dev=$(kdump_get_persistent_dev $_target) _new_dev=$(kdump_get_persistent_dev "$_target")
if [[ -z "$_new_dev" ]]; then if [[ -z "$_new_dev" ]]; then
perror "Get persistent device name failed" perror "Get persistent device name failed"
return 2 return 2
fi fi
_new_mntpoint="$(get_kdump_mntpoint_from_target $_target)" _new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")"
_dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) _dracut_args=$(lsinitrd "$TARGET_INITRD" -f usr/lib/dracut/build-parameter.txt)
if [[ -z "$_dracut_args" ]];then if [[ -z "$_dracut_args" ]];then
dwarn "Warning: No dracut arguments found in initrd" dwarn "Warning: No dracut arguments found in initrd"
return 0 return 0
@ -505,13 +505,14 @@ check_fs_modified()
# if --mount argument present then match old and new target, mount # if --mount argument present then match old and new target, mount
# point and file system. If any of them mismatches then rebuild # point and file system. If any of them mismatches then rebuild
echo $_dracut_args | grep -q "\-\-mount" echo "$_dracut_args" | grep -q "\-\-mount"
if [[ $? -eq 0 ]];then if [[ $? -eq 0 ]];then
set -- $(echo $_dracut_args | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) # shellcheck disable=SC2046
set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3)
_old_dev=$1 _old_dev=$1
_old_mntpoint=$2 _old_mntpoint=$2
_old_fstype=$3 _old_fstype=$3
[[ $_new_dev = $_old_dev && $_new_mntpoint = $_old_mntpoint && $_new_fstype = $_old_fstype ]] && return 0 [[ $_new_dev = "$_old_dev" && $_new_mntpoint = "$_old_mntpoint" && $_new_fstype = "$_old_fstype" ]] && return 0
# otherwise rebuild if target device is not a root device # otherwise rebuild if target device is not a root device
else else
[[ "$_target" = "$(get_root_fs_device)" ]] && return 0 [[ "$_target" = "$(get_root_fs_device)" ]] && return 0
@ -590,7 +591,7 @@ check_rebuild()
#check to see if dependent files has been modified #check to see if dependent files has been modified
#since last build of the image file #since last build of the image file
if [[ -f $TARGET_INITRD ]]; then if [[ -f $TARGET_INITRD ]]; then
image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null) image_time=$(stat -c "%Y" "$TARGET_INITRD" 2>/dev/null)
#in case of fadump mode, check whether the default/target #in case of fadump mode, check whether the default/target
#initrd is already built with dump capture capability #initrd is already built with dump capture capability
@ -649,7 +650,7 @@ function remove_kdump_kernel_key()
return return
fi fi
keyctl unlink $KDUMP_KEY_ID %:.ima keyctl unlink "$KDUMP_KEY_ID" %:.ima
} }
# Load the kdump kernel specified in /etc/sysconfig/kdump # Load the kdump kernel specified in /etc/sysconfig/kdump
@ -682,9 +683,10 @@ load_kdump()
PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}: ' PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}: '
set -x set -x
# shellcheck disable=SC2086
$KEXEC $KEXEC_ARGS $standard_kexec_args \ $KEXEC $KEXEC_ARGS $standard_kexec_args \
--command-line="$KDUMP_COMMANDLINE" \ --command-line="$KDUMP_COMMANDLINE" \
--initrd=$TARGET_INITRD $KDUMP_KERNEL --initrd="$TARGET_INITRD" "$KDUMP_KERNEL"
ret=$? ret=$?
set +x set +x
@ -709,7 +711,7 @@ check_ssh_config()
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
if [[ -f "$config_val" ]]; then if [[ -f "$config_val" ]]; then
# canonicalize the path # canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val")
else else
dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'"
fi fi
@ -726,7 +728,7 @@ check_ssh_config()
done <<< "$(kdump_read_conf)" done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps #make sure they've configured kdump.conf for ssh dumps
local SSH_TARGET=$(echo -n $DUMP_TARGET | sed -n '/.*@/p') local SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p')
if [[ -z "$SSH_TARGET" ]]; then if [[ -z "$SSH_TARGET" ]]; then
return 1 return 1
fi fi
@ -746,7 +748,7 @@ check_and_wait_network_ready()
local errmsg local errmsg
while true; do while true; do
errmsg=$(ssh -i $SSH_KEY_LOCATION -o BatchMode=yes $DUMP_TARGET mkdir -p $SAVE_PATH 2>&1) errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1)
retval=$? retval=$?
# ssh exits with the exit status of the remote command or with 255 if an error occurred # ssh exits with the exit status of the remote command or with 255 if an error occurred
@ -759,7 +761,7 @@ check_and_wait_network_ready()
# if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa
ddebug "$errmsg" ddebug "$errmsg"
echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\""
return 1 return 1
@ -808,16 +810,16 @@ propagate_ssh_key()
dinfo "Using existing keys..." dinfo "Using existing keys..."
else else
dinfo "Generating new ssh keys... " dinfo "Generating new ssh keys... "
/usr/bin/ssh-keygen -t rsa -f $KEYFILE -N "" 2>&1 > /dev/null /usr/bin/ssh-keygen -t rsa -f "$KEYFILE" -N "" 2>&1 > /dev/null
dinfo "done." dinfo "done."
fi fi
#now find the target ssh user and server to contact. #now find the target ssh user and server to contact.
SSH_USER=$(echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1) SSH_USER=$(echo "$DUMP_TARGET" | cut -d@ -f1)
SSH_SERVER=$(echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/') SSH_SERVER=$(echo "$DUMP_TARGET" | sed -e's/\(.*@\)\(.*$\)/\2/')
#now send the found key to the found server #now send the found key to the found server
ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER ssh-copy-id -i "$KEYFILE" "$SSH_USER@$SSH_SERVER"
RET=$? RET=$?
if [[ $RET == 0 ]]; then if [[ $RET == 0 ]]; then
dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER"
@ -836,7 +838,7 @@ show_reserved_mem()
mem=$(</sys/kernel/kexec_crash_size) mem=$(</sys/kernel/kexec_crash_size)
mem_mb=$((mem / 1024 / 1024)) mem_mb=$((mem / 1024 / 1024))
dinfo "Reserved "$mem_mb"MB memory for crash kernel" dinfo "Reserved ${mem_mb}MB memory for crash kernel"
} }
check_current_fadump_status() check_current_fadump_status()
@ -869,8 +871,8 @@ save_raw()
derror "raw partition $raw_target not found" derror "raw partition $raw_target not found"
return 1 return 1
} }
check_fs=$(lsblk --nodeps -npo FSTYPE $raw_target) check_fs=$(lsblk --nodeps -npo FSTYPE "$raw_target")
if [[ $(echo $check_fs | wc -w) -ne 0 ]]; then if [[ $(echo "$check_fs" | wc -w) -ne 0 ]]; then
dwarn "Warning: Detected '$check_fs' signature on $raw_target, data loss is expected." dwarn "Warning: Detected '$check_fs' signature on $raw_target, data loss is expected."
return 0 return 0
fi fi
@ -886,11 +888,11 @@ save_raw()
derror "failed to create $coredir" derror "failed to create $coredir"
return 1 return 1
} }
if makedumpfile -R $coredir/vmcore <$raw_target >/dev/null 2>&1; then if makedumpfile -R "$coredir/vmcore" < "$raw_target" >/dev/null 2>&1; then
# dump found # dump found
dinfo "Dump saved to $coredir/vmcore" dinfo "Dump saved to $coredir/vmcore"
# wipe makedumpfile header # wipe makedumpfile header
dd if=/dev/zero of=$raw_target bs=1b count=1 2>/dev/null dd if=/dev/zero of="$raw_target" bs=1b count=1 2>/dev/null
else else
rm -rf "$coredir" rm -rf "$coredir"
fi fi
@ -904,7 +906,7 @@ local_fs_dump_target()
_target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf)
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo $_target|awk '{print $2}' echo "$_target" | awk '{print $2}'
fi fi
} }
@ -919,7 +921,7 @@ path_to_be_relabeled()
_target=$(local_fs_dump_target) _target=$(local_fs_dump_target)
if [[ -n "$_target" ]]; then if [[ -n "$_target" ]]; then
_mnt=$(get_mntpoint_from_target $_target) _mnt=$(get_mntpoint_from_target "$_target")
if ! is_mounted "$_mnt"; then if ! is_mounted "$_mnt"; then
return return
fi fi
@ -930,9 +932,9 @@ path_to_be_relabeled()
_path=$(get_save_path) _path=$(get_save_path)
# if $_path is masked by other mount, we will not relabel it. # if $_path is masked by other mount, we will not relabel it.
_rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }') _rmnt=$(df "$_mnt/$_path" 2>/dev/null | tail -1 | awk '{ print $NF }')
if [[ "$_rmnt" == "$_mnt" ]]; then if [[ "$_rmnt" == "$_mnt" ]]; then
echo $_mnt/$_path echo "$_mnt/$_path"
fi fi
} }

View File

@ -60,9 +60,9 @@ add_dracut_sshkey() {
to_mount() { to_mount() {
local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev
_new_mntpoint=$(get_kdump_mntpoint_from_target $_target) _new_mntpoint=$(get_kdump_mntpoint_from_target "$_target")
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}" _fstype="${_fstype:-$(get_fs_type_from_target "$_target")}"
_options="${_options:-$(get_mntopt_from_target $_target)}" _options="${_options:-$(get_mntopt_from_target "$_target")}"
_options="${_options:-defaults}" _options="${_options:-defaults}"
if [[ "$_fstype" == "nfs"* ]]; then if [[ "$_fstype" == "nfs"* ]]; then
@ -72,8 +72,8 @@ to_mount() {
_sed_cmd+='s/,clientaddr=[^,]*//;' _sed_cmd+='s/,clientaddr=[^,]*//;'
else else
# for non-nfs _target converting to use udev persistent name # for non-nfs _target converting to use udev persistent name
_pdev="$(kdump_get_persistent_dev $_target)" _pdev="$(kdump_get_persistent_dev "$_target")"
if [[ -z "$_pdev" ]]; then if [[ -z $_pdev ]]; then
return 1 return 1
fi fi
fi fi
@ -114,19 +114,19 @@ mkdir_save_path_ssh()
{ {
local _opt _dir local _opt _dir
_opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes)
ssh -qn "${_opt[@]}" $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" 2>&1 > /dev/null
_ret=$? _ret=$?
if [[ $_ret -ne 0 ]]; then if [[ $_ret -ne 0 ]]; then
perror_exit "mkdir failed on $1:$SAVE_PATH" perror_exit "mkdir failed on $1:$SAVE_PATH"
fi fi
#check whether user has write permission on $1:$SAVE_PATH #check whether user has write permission on $1:$SAVE_PATH
_dir=$(ssh -qn "${_opt[@]}" $1 mktemp -dqp $SAVE_PATH 2>/dev/null) _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null)
_ret=$? _ret=$?
if [[ $_ret -ne 0 ]]; then if [[ $_ret -ne 0 ]]; then
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination"
fi fi
ssh -qn "${_opt[@]}" $1 rmdir $_dir ssh -qn "${_opt[@]}" "$1" rmdir "$_dir"
return 0 return 0
} }
@ -168,7 +168,7 @@ check_size() {
perror_exit "Check dump target size failed" perror_exit "Check dump target size failed"
fi fi
if [[ $avail -lt $memtotal ]]; then if [[ "$avail" -lt "$memtotal" ]]; then
dwarn "Warning: There might not be enough space to save a vmcore." dwarn "Warning: There might not be enough space to save a vmcore."
dwarn " The size of $2 should be greater than $memtotal kilo bytes." dwarn " The size of $2 should be greater than $memtotal kilo bytes."
fi fi
@ -206,9 +206,9 @@ mount_failure()
check_user_configured_target() check_user_configured_target()
{ {
local _target=$1 _cfg_fs_type=$2 _mounted local _target=$1 _cfg_fs_type=$2 _mounted
local _mnt=$(get_mntpoint_from_target $_target) local _mnt=$(get_mntpoint_from_target "$_target")
local _opt=$(get_mntopt_from_target $_target) local _opt=$(get_mntopt_from_target "$_target")
local _fstype=$(get_fs_type_from_target $_target) local _fstype=$(get_fs_type_from_target "$_target")
if [[ -n "$_fstype" ]]; then if [[ -n "$_fstype" ]]; then
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
@ -227,7 +227,7 @@ check_user_configured_target()
if [[ -n "$_mnt" ]]; then if [[ -n "$_mnt" ]]; then
if ! is_mounted "$_mnt"; then if ! is_mounted "$_mnt"; then
if [[ $_opt = *",noauto"* ]]; then if [[ $_opt = *",noauto"* ]]; then
mount $_mnt mount "$_mnt"
[[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype" [[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype"
_mounted=$_mnt _mounted=$_mnt
else else
@ -236,8 +236,8 @@ check_user_configured_target()
fi fi
else else
_mnt=$MKDUMPRD_TMPMNT _mnt=$MKDUMPRD_TMPMNT
mkdir -p $_mnt mkdir -p "$_mnt"
mount $_target $_mnt -t $_fstype -o defaults mount "$_target" "$_mnt" -t "$_fstype" -o defaults
[[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype" [[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype"
_mounted=$_mnt _mounted=$_mnt
fi fi
@ -251,7 +251,7 @@ check_user_configured_target()
# Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway
if [[ -n "$_mounted" ]]; then if [[ -n "$_mounted" ]]; then
umount -f -- $_mounted umount -f -- "$_mounted"
fi fi
} }
@ -276,13 +276,14 @@ verify_core_collector() {
_params="$_params vmcore dumpfile" _params="$_params vmcore dumpfile"
fi fi
# shellcheck disable=SC2086
if ! $_cmd --check-params $_params; then if ! $_cmd --check-params $_params; then
perror_exit "makedumpfile parameter check failed." perror_exit "makedumpfile parameter check failed."
fi fi
} }
add_mount() { add_mount() {
local _mnt=$(to_mount $@) local _mnt=$(to_mount "$@")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
exit 1 exit 1
@ -299,15 +300,15 @@ handle_default_dump_target()
is_user_configured_dump_target && return is_user_configured_dump_target && return
check_save_path_fs $SAVE_PATH check_save_path_fs "$SAVE_PATH"
_save_path=$(get_bind_mount_source $SAVE_PATH) _save_path=$(get_bind_mount_source "$SAVE_PATH")
_target=$(get_target_from_path $_save_path) _target=$(get_target_from_path "$_save_path")
_mntpoint=$(get_mntpoint_from_target $_target) _mntpoint=$(get_mntpoint_from_target "$_target")
SAVE_PATH=${_save_path##"$_mntpoint"} SAVE_PATH=${_save_path##"$_mntpoint"}
add_mount "$_target" add_mount "$_target"
check_size fs $_target check_size fs "$_target"
} }
# $1: function name # $1: function name
@ -317,8 +318,8 @@ for_each_block_target()
for dev in $(get_kdump_targets); do for dev in $(get_kdump_targets); do
[[ -b "$dev" ]] || continue [[ -b "$dev" ]] || continue
majmin=$(get_maj_min $dev) majmin=$(get_maj_min "$dev")
check_block_and_slaves $1 $majmin && return 1 check_block_and_slaves "$1" "$majmin" && return 1
done done
return 0 return 0
@ -328,14 +329,14 @@ for_each_block_target()
#return false if unresettable. #return false if unresettable.
is_unresettable() is_unresettable()
{ {
local path="/sys/$(udevadm info --query=all --path=/sys/dev/block/$1 | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" local path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
local resettable=1 local resettable=1
if [[ -f "$path" ]] if [[ -f "$path" ]]
then then
resettable="$(<"$path")" resettable="$(<"$path")"
[[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && {
local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}') local device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}')
derror "Error: Can not save vmcore because device $device is unresettable" derror "Error: Can not save vmcore because device $device is unresettable"
return 0 return 0
} }
@ -387,7 +388,7 @@ fi
keyfile=$(kdump_get_conf_val sshkey) keyfile=$(kdump_get_conf_val sshkey)
if [[ -f "$keyfile" ]]; then if [[ -f "$keyfile" ]]; then
# canonicalize the path # canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile")
fi fi
while read -r config_opt config_val; while read -r config_opt config_val;
@ -403,21 +404,21 @@ do
;; ;;
raw) raw)
# checking raw disk writable # checking raw disk writable
dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || {
perror_exit "Bad raw disk $config_val" perror_exit "Bad raw disk $config_val"
} }
_praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val) _praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val")
if [[ -z "$_praw" ]]; then if [[ -z $_praw ]]; then
exit 1 exit 1
fi fi
add_dracut_arg "--device" "$_praw" add_dracut_arg "--device" "$_praw"
check_size raw $config_val check_size raw "$config_val"
;; ;;
ssh) ssh)
if strstr "$config_val" "@"; if strstr "$config_val" "@";
then then
mkdir_save_path_ssh $config_val mkdir_save_path_ssh "$config_val"
check_size ssh $config_val check_size ssh "$config_val"
add_dracut_sshkey "$SSH_KEY_LOCATION" add_dracut_sshkey "$SSH_KEY_LOCATION"
else else
perror_exit "Bad ssh dump target $config_val" perror_exit "Bad ssh dump target $config_val"
@ -451,7 +452,7 @@ fi
if ! is_fadump_capable; then if ! is_fadump_capable; then
# The 2nd rootfs mount stays behind the normal dump target mount, # The 2nd rootfs mount stays behind the normal dump target mount,
# so it doesn't affect the logic of check_dump_fs_modified(). # so it doesn't affect the logic of check_dump_fs_modified().
is_dump_to_rootfs && add_mount "$(to_dev_name $(get_root_fs_device))" is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")"
add_dracut_arg "--no-hostonly-default-device" add_dracut_arg "--no-hostonly-default-device"
fi fi