bash scripts: replace '[ ]' with '[[ ]]' for bash scripts

upstream: fedora
resolves: bz2003832
conflict:
    function load_kdump_kernel_key() not presented in rhel9,
    so related patch hunk are removed.

commit 70978c00e5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 17:20:51 2021 +0800

    bash scripts: replace '[ ]' with '[[ ]]' for bash scripts

    kdumpctl, mkdumprd, *-module-setup.sh only target bash, since they
    only run in first kernel and depend on dracut, and dracut depends
    on bash. So use '[[ ]]' to replace '[ ]'.

    This is a batch update done with following command:
    `sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdumpctl, mkdumprd, *-module-setup.sh`
    and replaced [ ... -a ... ] with [[ ... ]] && [[ ... ]] manually.

    See https://tldp.org/LDP/abs/html/testconstructs.html for more details
    on '[[ ]]', it's more versatile, safer, and slightly faster than '[ ]'.

    This will also help shfmt to clean up the code in later commits.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
Tao Liu 2021-11-09 21:13:59 +08:00
parent 20c694278f
commit dcb59c30d5
5 changed files with 192 additions and 192 deletions

View File

@ -6,8 +6,8 @@ KDUMP_KERNEL=""
KDUMP_INITRD="" KDUMP_INITRD=""
check() { check() {
if [ ! -f /etc/sysconfig/kdump ] || [ ! -f /lib/kdump/kdump-lib.sh ]\ if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]]\
|| [ -n "${IN_KDUMP}" ] || [[ -n "${IN_KDUMP}" ]]
then then
return 1 return 1
fi fi
@ -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
@ -33,12 +33,12 @@ prepare_kernel_initrd() {
install() { install() {
prepare_kernel_initrd prepare_kernel_initrd
if [ ! -f "$KDUMP_KERNEL" ]; then if [[ ! -f "$KDUMP_KERNEL" ]]; then
derror "Could not find required kernel for earlykdump," \ derror "Could not find required kernel for earlykdump," \
"earlykdump will not work!" "earlykdump will not work!"
return 1 return 1
fi fi
if [ ! -f "$KDUMP_INITRD" ]; then if [[ ! -f "$KDUMP_INITRD" ]]; then
derror "Could not find required kdump initramfs for earlykdump," \ derror "Could not find required kdump initramfs for earlykdump," \
"please ensure kdump initramfs is generated first," \ "please ensure kdump initramfs is generated first," \
"earlykdump will not work!" "earlykdump will not work!"

View File

@ -11,7 +11,7 @@ kdump_module_init() {
check() { check() {
[[ $debug ]] && set -x [[ $debug ]] && set -x
#kdumpctl sets this explicitly #kdumpctl sets this explicitly
if [ -z "$IN_KDUMP" ] || [ ! -f /etc/kdump.conf ] if [[ -z "$IN_KDUMP" ]] || [[ ! -f /etc/kdump.conf ]]
then then
return 1 return 1
fi fi
@ -41,11 +41,11 @@ depends() {
_dep="$_dep ssh-client" _dep="$_dep ssh-client"
fi fi
if [ "$(uname -m)" = "s390x" ]; then if [[ "$(uname -m)" = "s390x" ]]; then
_dep="$_dep znet" _dep="$_dep znet"
fi fi
if [ -n "$( ls -A /sys/class/drm 2>/dev/null )" ] || [ -d /sys/module/hyperv_fb ]; then if [[ -n "$( ls -A /sys/class/drm 2>/dev/null )" ]] || [[ -d /sys/module/hyperv_fb ]]; then
add_opt_module drm add_opt_module drm
fi fi
@ -57,19 +57,19 @@ depends() {
} }
kdump_is_bridge() { kdump_is_bridge() {
[ -d /sys/class/net/"$1"/bridge ] [[ -d /sys/class/net/"$1"/bridge ]]
} }
kdump_is_bond() { kdump_is_bond() {
[ -d /sys/class/net/"$1"/bonding ] [[ -d /sys/class/net/"$1"/bonding ]]
} }
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() {
[ -f /proc/net/vlan/"$1" ] [[ -f /proc/net/vlan/"$1" ]]
} }
# $1: netdev name # $1: netdev name
@ -78,7 +78,7 @@ source_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!"
@ -102,19 +102,19 @@ kdump_setup_dns() {
else else
dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script"
source_ifcfg_file "$_netdev" source_ifcfg_file "$_netdev"
[ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" [[ -n "$DNS1" ]] && echo "nameserver=$DNS1" > "$_dnsfile"
[ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" [[ -n "$DNS2" ]] && echo "nameserver=$DNS2" >> "$_dnsfile"
fi fi
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 | cut -d' ' -f2)
[ -z "$_dns" ] && continue [[ -z "$_dns" ]] && continue
if [ ! -f $_dnsfile ] || ! grep -q "$_dns" "$_dnsfile" ; then if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then
echo "nameserver=$_dns" >> "$_dnsfile" echo "nameserver=$_dns" >> "$_dnsfile"
fi fi
done < "/etc/resolv.conf" done < "/etc/resolv.conf"
@ -243,11 +243,11 @@ kdump_static_ip() {
_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
# _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/"
_netmask=${_ipaddr#*\/} _netmask=${_ipaddr#*\/}
_srcaddr="[$_srcaddr]" _srcaddr="[$_srcaddr]"
@ -268,7 +268,7 @@ kdump_static_ip() {
while read -r _route; do while read -r _route; do
_target=$(echo $_route | cut -d ' ' -f1) _target=$(echo $_route | cut -d ' ' -f1)
_nexthop=$(echo $_route | cut -d ' ' -f3) _nexthop=$(echo $_route | cut -d ' ' -f3)
if [ "x" != "x"$_ipv6_flag ]; then if [[ "x" != "x"$_ipv6_flag ]]; then
_target="[$_target]" _target="[$_target]"
_nexthop="[$_nexthop]" _nexthop="[$_nexthop]"
fi fi
@ -297,7 +297,7 @@ kdump_handle_mulitpath_route() {
if [[ "$_weight" -gt "$_max_weight" ]]; then if [[ "$_weight" -gt "$_max_weight" ]]; then
_nexthop=$(echo "$_route" | cut -d ' ' -f3) _nexthop=$(echo "$_route" | cut -d ' ' -f3)
_max_weight=$_weight _max_weight=$_weight
if [ "x" != "x"$_ipv6_flag ]; then if [[ "x" != "x"$_ipv6_flag ]]; then
_rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic"
else else
_rule="rd.route=$_target:$_nexthop:$kdumpnic" _rule="rd.route=$_target:$_nexthop:$kdumpnic"
@ -322,7 +322,7 @@ kdump_get_mac_addr() {
#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"
else else
@ -420,7 +420,7 @@ kdump_setup_team() {
#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
@ -460,25 +460,25 @@ find_online_znet_device() {
local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices"
local NETWORK_DEVICES d ifname ONLINE local NETWORK_DEVICES d ifname ONLINE
[ ! -d "$CCWGROUPBUS_DEVICEDIR" ] && return [[ ! -d "$CCWGROUPBUS_DEVICEDIR" ]] && return
NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR)
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
# determine interface name, if there (only for qeth and if # determine interface name, if there (only for qeth and if
# 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
echo -n "$ifname" echo -n "$ifname"
} }
@ -530,7 +530,7 @@ 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 | cut -d' ' -f1)
@ -565,7 +565,7 @@ kdump_install_net() {
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
@ -580,7 +580,7 @@ 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
@ -603,7 +603,7 @@ kdump_install_net() {
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
@ -615,8 +615,8 @@ kdump_install_net() {
# the default gate way for network dump, eth1 in the fence kdump path will # the default gate way for network dump, eth1 in the fence kdump path will
# call kdump_install_net again and we don't want eth1 to be the default # call kdump_install_net again and we don't want eth1 to be the default
# 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
@ -624,21 +624,21 @@ kdump_install_net() {
# install etc/kdump/pre.d and /etc/kdump/post.d # install etc/kdump/pre.d and /etc/kdump/post.d
kdump_install_pre_post_conf() { 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
done done
fi fi
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
done done
@ -667,7 +667,7 @@ default_dump_target_install_conf()
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
_save_path=${_save_path##"$_mntpoint"} _save_path=${_save_path##"$_mntpoint"}
fi fi
@ -748,10 +748,10 @@ kdump_get_iscsi_initiator() {
local _initiator local _initiator
local initiator_conf="/etc/iscsi/initiatorname.iscsi" local initiator_conf="/etc/iscsi/initiatorname.iscsi"
[ -f "$initiator_conf" ] || return 1 [[ -f "$initiator_conf" ]] || return 1
while read -r _initiator; do while read -r _initiator; do
[ -z "${_initiator%%#*}" ] && continue # Skip comment lines [[ -z "${_initiator%%#*}" ]] && continue # Skip comment lines
case $_initiator in case $_initiator in
InitiatorName=*) InitiatorName=*)
@ -767,7 +767,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() {
@ -800,18 +800,18 @@ kdump_setup_iscsi_device() {
# 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"
kdump_install_net "$tgt_ipaddr" kdump_install_net "$tgt_ipaddr"
@ -834,7 +834,7 @@ kdump_setup_iscsi_device() {
# Setup initator # Setup initator
initiator_str=$(kdump_get_iscsi_initiator) initiator_str=$(kdump_get_iscsi_initiator)
[ $? -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
@ -875,7 +875,7 @@ get_alias() {
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
@ -892,7 +892,7 @@ is_localhost() {
hostnames="$hostnames $shortnames $aliasname" hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do for name in ${hostnames}; do
if [ "$name" == "$nodename" ]; then if [[ "$name" == "$nodename" ]]; then
return 0 return 0
fi fi
done done
@ -925,7 +925,7 @@ get_pcs_fence_kdump_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
@ -963,7 +963,7 @@ kdump_configure_fence_kdump () {
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
@ -989,7 +989,7 @@ 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
@ -1001,7 +1001,7 @@ 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

214
kdumpctl
View File

@ -27,7 +27,7 @@ standard_kexec_args="-d -p"
# Some default values in case /etc/sysconfig/kdump doesn't include # Some default values in case /etc/sysconfig/kdump doesn't include
KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug" KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug"
if [ -f /etc/sysconfig/kdump ]; then if [[ -f /etc/sysconfig/kdump ]]; then
. /etc/sysconfig/kdump . /etc/sysconfig/kdump
fi fi
@ -38,7 +38,7 @@ fi
#initiate the kdump logger #initiate the kdump logger
dlog_init dlog_init
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
echo "failed to initiate the kdump logger." echo "failed to initiate the kdump logger."
exit 1 exit 1
fi fi
@ -48,7 +48,7 @@ single_instance_lock()
local rc timeout=5 local rc timeout=5
exec 9>/var/lock/kdump exec 9>/var/lock/kdump
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Create file lock failed" derror "Create file lock failed"
exit 1 exit 1
fi fi
@ -56,7 +56,7 @@ single_instance_lock()
flock -n 9 flock -n 9
rc=$? rc=$?
while [ $rc -ne 0 ]; do while [[ $rc -ne 0 ]]; do
dinfo "Another app is currently holding the kdump lock; waiting for it to exit..." dinfo "Another app is currently holding the kdump lock; waiting for it to exit..."
flock -w $timeout 9 flock -w $timeout 9
rc=$? rc=$?
@ -81,7 +81,7 @@ save_core()
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
@ -91,12 +91,12 @@ save_core()
# pass the dmesg to Abrt tool if exists, in order # pass the dmesg to Abrt tool if exists, in order
# to collect the kernel oops message. # to collect the kernel oops message.
# 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
fi fi
@ -122,7 +122,7 @@ 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
fi fi
@ -141,7 +141,7 @@ rebuild_initrd()
return 1 return 1
fi fi
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
rebuild_fadump_initrd rebuild_fadump_initrd
else else
rebuild_kdump_initrd rebuild_kdump_initrd
@ -154,7 +154,7 @@ rebuild_initrd()
check_exist() check_exist()
{ {
for file in $1; do for file in $1; do
if [ ! -e "$file" ]; then if [[ ! -e "$file" ]]; then
derror "Error: $file not found." derror "Error: $file not found."
return 1 return 1
fi fi
@ -165,7 +165,7 @@ check_exist()
check_executable() check_executable()
{ {
for file in $1; do for file in $1; do
if [ ! -x "$file" ]; then if [[ ! -x "$file" ]]; then
derror "Error: $file is not executable." derror "Error: $file is not executable."
return 1 return 1
fi fi
@ -176,16 +176,16 @@ backup_default_initrd()
{ {
ddebug "backup default initrd: $DEFAULT_INITRD" ddebug "backup default initrd: $DEFAULT_INITRD"
if [ ! -f "$DEFAULT_INITRD" ]; then if [[ ! -f "$DEFAULT_INITRD" ]]; then
return return
fi fi
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
@ -196,17 +196,17 @@ restore_default_initrd()
{ {
ddebug "restore default initrd: $DEFAULT_INITRD" ddebug "restore default initrd: $DEFAULT_INITRD"
if [ ! -f "$DEFAULT_INITRD" ]; then if [[ ! -f "$DEFAULT_INITRD" ]]; then
return return
fi fi
# If a backup initrd exists, we must be switching back from # If a backup initrd exists, we must be switching back from
# fadump to kdump. Restore the original default initrd. # fadump to kdump. Restore the original default initrd.
if [ -f $DEFAULT_INITRD_BAK ] && [ -f $INITRD_CHECKSUM_LOCATION ]; then if [[ -f $DEFAULT_INITRD_BAK ]] && [[ -f $INITRD_CHECKSUM_LOCATION ]]; then
# verify checksum before restoring # verify checksum before restoring
backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }') backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }')
default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION") default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION")
if [ "$default_checksum" != "$backup_checksum" ]; then if [[ "$default_checksum" != "$backup_checksum" ]]; then
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
@ -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
@ -234,7 +234,7 @@ check_config()
fi fi
;; ;;
raw) raw)
if [ -d "/proc/device-tree/ibm,opal/dump" ]; then if [[ -d "/proc/device-tree/ibm,opal/dump" ]]; then
dwarn "WARNING: Won't capture opalcore when 'raw' dump target is used." dwarn "WARNING: Won't capture opalcore when 'raw' dump target is used."
fi fi
config_opt=_target config_opt=_target
@ -262,8 +262,8 @@ check_config()
return 1 return 1
fi fi
if [ -n "${_opt_rec[$config_opt]}" ]; then if [[ -n "${_opt_rec[$config_opt]}" ]]; then
if [ $config_opt == _target ]; then if [[ $config_opt == _target ]]; then
derror "More than one dump targets specified" derror "More than one dump targets specified"
else else
derror "Duplicated kdump config value of option $config_opt" derror "Duplicated kdump config value of option $config_opt"
@ -292,13 +292,13 @@ get_pcs_cluster_modified_files()
time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date) time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date)
if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then if [[ -n $time_stamp ]] && [[ $time_stamp -gt $image_time ]]; then
modified_files="cluster-cib" modified_files="cluster-cib"
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
@ -309,13 +309,13 @@ get_pcs_cluster_modified_files()
setup_initrd() setup_initrd()
{ {
prepare_kdump_bootinfo prepare_kdump_bootinfo
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "failed to prepare for kdump bootinfo." derror "failed to prepare for kdump bootinfo."
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"
# backup initrd for reference before replacing it # backup initrd for reference before replacing it
@ -341,16 +341,16 @@ check_files_modified()
EXTRA_BINS=$(kdump_get_conf_val kdump_post) EXTRA_BINS=$(kdump_get_conf_val kdump_post)
CHECK_FILES=$(kdump_get_conf_val kdump_pre) CHECK_FILES=$(kdump_get_conf_val kdump_pre)
HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/"
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
POST_FILES="$POST_FILES $file" POST_FILES="$POST_FILES $file"
fi fi
done done
fi fi
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
PRE_FILES="$PRE_FILES $file" PRE_FILES="$PRE_FILES $file"
fi fi
done done
@ -367,8 +367,8 @@ check_files_modified()
# Check for any updated extra module # Check for any updated extra module
EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" EXTRA_MODULES="$(kdump_get_conf_val extra_modules)"
if [ -n "$EXTRA_MODULES" ]; then if [[ -n "$EXTRA_MODULES" ]]; then
if [ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]; then if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then
files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep"
fi fi
for _module in $EXTRA_MODULES; do for _module in $EXTRA_MODULES; do
@ -390,18 +390,18 @@ check_files_modified()
# HOOKS is mandatory and need to check the modification time # HOOKS is mandatory and need to check the modification time
files="$files $HOOKS" files="$files $HOOKS"
check_exist "$files" && check_executable "$EXTRA_BINS" check_exist "$files" && check_executable "$EXTRA_BINS"
[ $? -ne 0 ] && return 2 [[ $? -ne 0 ]] && return 2
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
fi fi
@ -410,7 +410,7 @@ check_files_modified()
fi fi
done done
if [ -n "$modified_files" ]; then if [[ -n "$modified_files" ]]; then
dinfo "Detected change(s) in the following file(s): $modified_files" dinfo "Detected change(s) in the following file(s): $modified_files"
return 1 return 1
fi fi
@ -441,7 +441,7 @@ check_drivers_modified()
# Include watchdog drivers if watchdog module is not omitted # Include watchdog drivers if watchdog module is not omitted
is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)"
[ -z "$_new_drivers" ] && return 0 [[ -z "$_new_drivers" ]] && return 0
if is_fadump_capable; then if is_fadump_capable; then
_old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')"
@ -455,7 +455,7 @@ check_drivers_modified()
# 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
if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then
@ -491,7 +491,7 @@ check_fs_modified()
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
@ -532,19 +532,19 @@ check_system_modified()
check_files_modified check_files_modified
ret=$? ret=$?
if [ $ret -ne 0 ]; then if [[ $ret -ne 0 ]]; then
return $ret return $ret
fi fi
check_fs_modified check_fs_modified
ret=$? ret=$?
if [ $ret -ne 0 ]; then if [[ $ret -ne 0 ]]; then
return $ret return $ret
fi fi
check_drivers_modified check_drivers_modified
ret=$? ret=$?
if [ $ret -ne 0 ]; then if [[ $ret -ne 0 ]]; then
return $ret return $ret
fi fi
@ -559,20 +559,20 @@ check_rebuild()
setup_initrd setup_initrd
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
return 1 return 1
fi fi
force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=$(kdump_get_conf_val force_no_rebuild)
force_no_rebuild=${force_no_rebuild:-0} force_no_rebuild=${force_no_rebuild:-0}
if [ "$force_no_rebuild" != "0" ] && [ "$force_no_rebuild" != "1" ];then if [[ "$force_no_rebuild" != "0" ]] && [[ "$force_no_rebuild" != "1" ]];then
derror "Error: force_no_rebuild value is invalid" derror "Error: force_no_rebuild value is invalid"
return 1 return 1
fi fi
force_rebuild=$(kdump_get_conf_val force_rebuild) force_rebuild=$(kdump_get_conf_val force_rebuild)
force_rebuild=${force_rebuild:-0} force_rebuild=${force_rebuild:-0}
if [ "$force_rebuild" != "0" ] && [ "$force_rebuild" != "1" ];then if [[ "$force_rebuild" != "0" ]] && [[ "$force_rebuild" != "1" ]];then
derror "Error: force_rebuild value is invalid" derror "Error: force_rebuild value is invalid"
return 1 return 1
fi fi
@ -583,37 +583,37 @@ check_rebuild()
fi fi
# Will not rebuild kdump initrd # Will not rebuild kdump initrd
if [ "$force_no_rebuild" == "1" ]; then if [[ "$force_no_rebuild" == "1" ]]; then
return 0 return 0
fi fi
#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
if [ "$DEFAULT_DUMP_MODE" == "fadump" ]; then if [[ "$DEFAULT_DUMP_MODE" == "fadump" ]]; then
capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$)
fi fi
fi fi
check_system_modified check_system_modified
ret=$? ret=$?
if [ $ret -eq 2 ]; then if [[ $ret -eq 2 ]]; then
return 1 return 1
elif [ $ret -eq 1 ];then elif [[ $ret -eq 1 ]];then
system_modified="1" system_modified="1"
fi fi
if [ $image_time -eq 0 ]; then if [[ $image_time -eq 0 ]]; then
dinfo "No kdump initial ramdisk found." dinfo "No kdump initial ramdisk found."
elif [ "$capture_capable_initrd" == "0" ]; then elif [[ "$capture_capable_initrd" == "0" ]]; then
dinfo "Rebuild $TARGET_INITRD with dump capture support" dinfo "Rebuild $TARGET_INITRD with dump capture support"
elif [ "$force_rebuild" != "0" ]; then elif [[ "$force_rebuild" != "0" ]]; then
dinfo "Force rebuild $TARGET_INITRD" dinfo "Force rebuild $TARGET_INITRD"
elif [ "$system_modified" != "0" ]; then elif [[ "$system_modified" != "0" ]]; then
: :
else else
return 0 return 0
@ -661,7 +661,7 @@ load_kdump()
set +x set +x
exec 2>&12 12>&- exec 2>&12 12>&-
if [ $ret == 0 ]; then if [[ $ret == 0 ]]; then
dinfo "kexec: loaded kdump kernel" dinfo "kexec: loaded kdump kernel"
return 0 return 0
else else
@ -676,7 +676,7 @@ check_ssh_config()
case "$config_opt" in case "$config_opt" in
sshkey) sshkey)
# 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
@ -696,7 +696,7 @@ check_ssh_config()
#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
return 0 return 0
@ -719,9 +719,9 @@ check_and_wait_network_ready()
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
if [ $retval -eq 0 ]; then if [[ $retval -eq 0 ]]; then
return 0 return 0
elif [ $retval -ne 255 ]; then elif [[ $retval -ne 255 ]]; then
derror "Could not create $DUMP_TARGET:$SAVE_PATH, you should check the privilege on server side" derror "Could not create $DUMP_TARGET:$SAVE_PATH, you should check the privilege on server side"
return 1 return 1
fi fi
@ -729,12 +729,12 @@ 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
fi fi
if [ $warn_once -eq 1 ]; then if [[ $warn_once -eq 1 ]]; then
dwarn "Network dump target is not usable, waiting for it to be ready..." dwarn "Network dump target is not usable, waiting for it to be ready..."
warn_once=0 warn_once=0
fi fi
@ -742,7 +742,7 @@ check_and_wait_network_ready()
cur=$(date +%s) cur=$(date +%s)
diff=$((cur - start_time)) diff=$((cur - start_time))
# 60s time out # 60s time out
if [ $diff -gt 180 ]; then if [[ $diff -gt 180 ]]; then
break; break;
fi fi
sleep 1 sleep 1
@ -755,7 +755,7 @@ check_and_wait_network_ready()
check_ssh_target() check_ssh_target()
{ {
check_and_wait_network_ready check_and_wait_network_ready
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
return 1 return 1
fi fi
return 0 return 0
@ -764,7 +764,7 @@ check_ssh_target()
propagate_ssh_key() propagate_ssh_key()
{ {
check_ssh_config check_ssh_config
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate"
exit 1 exit 1
fi fi
@ -773,7 +773,7 @@ propagate_ssh_key()
local errmsg="Failed to propagate ssh key" local errmsg="Failed to propagate ssh key"
#Check to see if we already created key, if not, create it. #Check to see if we already created key, if not, create it.
if [ -f $KEYFILE ]; then if [[ -f $KEYFILE ]]; then
dinfo "Using existing keys..." dinfo "Using existing keys..."
else else
dinfo "Generating new ssh keys... " dinfo "Generating new ssh keys... "
@ -788,7 +788,7 @@ propagate_ssh_key()
#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"
return 0 return 0
else else
@ -812,13 +812,13 @@ check_current_fadump_status()
{ {
# Check if firmware-assisted dump has been registered. # Check if firmware-assisted dump has been registered.
rc=$(<$FADUMP_REGISTER_SYS_NODE) rc=$(<$FADUMP_REGISTER_SYS_NODE)
[ $rc -eq 1 ] && return 0 [[ $rc -eq 1 ]] && return 0
return 1 return 1
} }
check_current_status() check_current_status()
{ {
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
check_current_fadump_status check_current_fadump_status
else else
check_current_kdump_status check_current_kdump_status
@ -833,8 +833,8 @@ save_raw()
local raw_target local raw_target
raw_target=$(kdump_get_conf_val raw) raw_target=$(kdump_get_conf_val raw)
[ -z "$raw_target" ] && return 0 [[ -z "$raw_target" ]] && return 0
[ -b "$raw_target" ] || { [[ -b "$raw_target" ]] || {
derror "raw partition $raw_target not found" derror "raw partition $raw_target not found"
return 1 return 1
} }
@ -844,14 +844,14 @@ save_raw()
return 0 return 0
fi fi
kdump_dir=$(kdump_get_conf_val path) kdump_dir=$(kdump_get_conf_val path)
if [ -z "${kdump_dir}" ]; then if [[ -z "${kdump_dir}" ]]; then
coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
else else
coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")"
fi fi
mkdir -p "$coredir" mkdir -p "$coredir"
[ -d "$coredir" ] || { [[ -d "$coredir" ]] || {
derror "failed to create $coredir" derror "failed to create $coredir"
return 1 return 1
} }
@ -872,7 +872,7 @@ local_fs_dump_target()
local _target local _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
} }
@ -900,7 +900,7 @@ 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
} }
@ -910,13 +910,13 @@ selinux_relabel()
local _path _i _attr local _path _i _attr
_path=$(path_to_be_relabeled) _path=$(path_to_be_relabeled)
if [ -z "$_path" ] || ! [ -d "$_path" ] ; then if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then
return return
fi fi
while IFS= read -r -d '' _i; do while IFS= read -r -d '' _i; do
_attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) _attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null)
if [ -z "$_attr" ]; then if [[ -z "$_attr" ]]; then
restorecon "$_i"; restorecon "$_i";
fi fi
done < <(find "$_path" -print0) done < <(find "$_path" -print0)
@ -929,13 +929,13 @@ check_fence_kdump_config()
local nodes=$(kdump_get_conf_val "fence_kdump_nodes") local nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do for node in $nodes; do
if [ "$node" = "$hostname" ]; then if [[ "$node" = "$hostname" ]]; then
derror "Option fence_kdump_nodes cannot contain $hostname" derror "Option fence_kdump_nodes cannot contain $hostname"
return 1 return 1
fi fi
# node can be ipaddr # node can be ipaddr
echo "$ipaddrs " | grep -q "$node " echo "$ipaddrs " | grep -q "$node "
if [ $? -eq 0 ]; then if [[ $? -eq 0 ]]; then
derror "Option fence_kdump_nodes cannot contain $node" derror "Option fence_kdump_nodes cannot contain $node"
return 1 return 1
fi fi
@ -946,7 +946,7 @@ check_fence_kdump_config()
check_dump_feasibility() check_dump_feasibility()
{ {
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
return 0 return 0
fi fi
@ -968,7 +968,7 @@ start_fadump()
start_dump() start_dump()
{ {
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
start_fadump start_fadump
else else
load_kdump load_kdump
@ -986,14 +986,14 @@ check_failure_action_config()
default_option=$(kdump_get_conf_val default) default_option=$(kdump_get_conf_val default)
failure_action=$(kdump_get_conf_val failure_action) failure_action=$(kdump_get_conf_val failure_action)
if [ -z "$failure_action" -a -z "$default_option" ]; then if [[ -z "$failure_action" ]] && [[ -z "$default_option" ]]; then
return 0 return 0
elif [ -n "$failure_action" -a -n "$default_option" ]; then elif [[ -n "$failure_action" ]] && [[ -n "$default_option" ]]; then
derror "Cannot specify 'failure_action' and 'default' option together" derror "Cannot specify 'failure_action' and 'default' option together"
return 1 return 1
fi fi
if [ -n "$default_option" ]; then if [[ -n "$default_option" ]]; then
option="default" option="default"
failure_action="$default_option" failure_action="$default_option"
fi fi
@ -1013,7 +1013,7 @@ check_final_action_config()
local final_action local final_action
final_action=$(kdump_get_conf_val final_action) final_action=$(kdump_get_conf_val final_action)
if [ -z "$final_action" ]; then if [[ -z "$final_action" ]]; then
return 0 return 0
else else
case "$final_action" in case "$final_action" in
@ -1030,13 +1030,13 @@ check_final_action_config()
start() start()
{ {
check_dump_feasibility check_dump_feasibility
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
check_config check_config
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1046,13 +1046,13 @@ start()
fi fi
save_raw save_raw
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
check_current_status check_current_status
if [ $? == 0 ]; then if [[ $? == 0 ]]; then
dwarn "Kdump already running: [WARNING]" dwarn "Kdump already running: [WARNING]"
return 0 return 0
fi fi
@ -1065,13 +1065,13 @@ start()
fi fi
check_rebuild check_rebuild
if [ $? != 0 ]; then if [[ $? != 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
start_dump start_dump
if [ $? != 0 ]; then if [[ $? != 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1082,18 +1082,18 @@ start()
reload() reload()
{ {
check_current_status check_current_status
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
dwarn "Kdump was not running: [WARNING]" dwarn "Kdump was not running: [WARNING]"
fi fi
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
reload_fadump reload_fadump
return $? return $?
else else
stop_kdump stop_kdump
fi fi
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Stopping kdump: [FAILED]" derror "Stopping kdump: [FAILED]"
return 1 return 1
fi fi
@ -1101,13 +1101,13 @@ reload()
dinfo "Stopping kdump: [OK]" dinfo "Stopping kdump: [OK]"
setup_initrd setup_initrd
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
start_dump start_dump
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1135,7 +1135,7 @@ stop_kdump()
$KEXEC -p -u $KEXEC -p -u
fi fi
if [ $? != 0 ]; then if [[ $? != 0 ]]; then
derror "kexec: failed to unload kdump kernel" derror "kexec: failed to unload kdump kernel"
return 1 return 1
fi fi
@ -1147,7 +1147,7 @@ stop_kdump()
reload_fadump() reload_fadump()
{ {
echo 1 > $FADUMP_REGISTER_SYS_NODE echo 1 > $FADUMP_REGISTER_SYS_NODE
if [ $? == 0 ]; then if [[ $? == 0 ]]; then
dinfo "fadump: re-registered successfully" dinfo "fadump: re-registered successfully"
return 0 return 0
else else
@ -1155,7 +1155,7 @@ reload_fadump()
# support is not enabled. Try stop/start from userspace # support is not enabled. Try stop/start from userspace
# to handle such scenario. # to handle such scenario.
stop_fadump stop_fadump
if [ $? == 0 ]; then if [[ $? == 0 ]]; then
start_fadump start_fadump
return $? return $?
fi fi
@ -1166,13 +1166,13 @@ reload_fadump()
stop() stop()
{ {
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
stop_fadump stop_fadump
else else
stop_kdump stop_kdump
fi fi
if [ $? != 0 ]; then if [[ $? != 0 ]]; then
derror "Stopping kdump: [FAILED]" derror "Stopping kdump: [FAILED]"
return 1 return 1
fi fi
@ -1183,7 +1183,7 @@ stop()
rebuild() { rebuild() {
check_config check_config
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
return 1 return 1
fi fi
@ -1194,7 +1194,7 @@ rebuild() {
fi fi
setup_initrd setup_initrd
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
return 1 return 1
fi fi
@ -1211,7 +1211,7 @@ do_estimate() {
local size_mb=$(( 1024 * 1024 )) local size_mb=$(( 1024 * 1024 ))
setup_initrd setup_initrd
if [ ! -f "$TARGET_INITRD" ]; then if [[ ! -f "$TARGET_INITRD" ]]; then
derror "kdumpctl estimate: kdump initramfs is not built yet." derror "kdumpctl estimate: kdump initramfs is not built yet."
exit 1 exit 1
fi fi
@ -1328,7 +1328,7 @@ reset_crashkernel() {
fi fi
} }
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then
derror "Error: No kdump config file found!" derror "Error: No kdump config file found!"
exit 1 exit 1
fi fi
@ -1340,7 +1340,7 @@ main ()
case "$1" in case "$1" in
start) start)
if [ -s /proc/vmcore ]; then if [[ -s /proc/vmcore ]]; then
save_core save_core
reboot reboot
else else

View File

@ -6,7 +6,7 @@
# Written by Cong Wang <amwang@redhat.com> # Written by Cong Wang <amwang@redhat.com>
# #
if [ -f /etc/sysconfig/kdump ]; then if [[ -f /etc/sysconfig/kdump ]]; then
. /etc/sysconfig/kdump . /etc/sysconfig/kdump
fi fi
@ -18,7 +18,7 @@ export IN_KDUMP=1
#initiate the kdump logger #initiate the kdump logger
dlog_init dlog_init
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
echo "failed to initiate the kdump logger." echo "failed to initiate the kdump logger."
exit 1 exit 1
fi fi
@ -73,7 +73,7 @@ to_mount() {
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
@ -116,14 +116,14 @@ mkdir_save_path_ssh()
_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
@ -164,11 +164,11 @@ check_size() {
return return
esac esac
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
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
@ -178,7 +178,7 @@ check_save_path_fs()
{ {
local _path=$1 local _path=$1
if [ ! -d $_path ]; then if [[ ! -d $_path ]]; then
perror_exit "Dump path $_path does not exist." perror_exit "Dump path $_path does not exist."
fi fi
} }
@ -190,7 +190,7 @@ mount_failure()
local _fstype=$3 local _fstype=$3
local msg="Failed to mount $_target" local msg="Failed to mount $_target"
if [ -n "$_mnt" ]; then if [[ -n "$_mnt" ]]; then
msg="$msg on $_mnt" msg="$msg on $_mnt"
fi fi
@ -210,11 +210,11 @@ check_user_configured_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
[[ $_fstype = "nfs"* ]] && _fstype=nfs [[ $_fstype = "nfs"* ]] && _fstype=nfs
if [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; then if [[ -n "$_cfg_fs_type" ]] && [[ "$_fstype" != "$_cfg_fs_type" ]]; then
perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\"" perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\""
fi fi
else else
@ -224,11 +224,11 @@ check_user_configured_target()
# For noauto mount, mount it inplace with default value. # For noauto mount, mount it inplace with default value.
# Else use the temporary target directory # Else use the temporary target directory
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
perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\""
@ -238,19 +238,19 @@ check_user_configured_target()
_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
# For user configured target, use $SAVE_PATH as the dump path within the target # For user configured target, use $SAVE_PATH as the dump path within the target
if [ ! -d "$_mnt/$SAVE_PATH" ]; then if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then
perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\""
fi fi
check_size fs "$_target" check_size fs "$_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
} }
@ -260,7 +260,7 @@ verify_core_collector() {
local _cmd="${1%% *}" local _cmd="${1%% *}"
local _params="${1#* }" local _params="${1#* }"
if [ "$_cmd" != "makedumpfile" ]; then if [[ "$_cmd" != "makedumpfile" ]]; then
if is_raw_dump_target; then if is_raw_dump_target; then
dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
fi fi
@ -284,7 +284,7 @@ verify_core_collector() {
add_mount() { add_mount() {
local _mnt=$(to_mount $@) local _mnt=$(to_mount $@)
if [ $? -ne 0 ]; then if [[ $? -ne 0 ]]; then
exit 1 exit 1
fi fi
@ -316,7 +316,7 @@ for_each_block_target()
local dev majmin local dev majmin
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
@ -331,10 +331,10 @@ 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 -a "$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
@ -359,7 +359,7 @@ check_resettable()
for_each_block_target is_unresettable for_each_block_target is_unresettable
_ret=$? _ret=$?
[ $_ret -eq 0 ] && return [[ $_ret -eq 0 ]] && return
return 1 return 1
} }
@ -385,7 +385,7 @@ fi
# firstly get right SSH_KEY_LOCATION # firstly get right SSH_KEY_LOCATION
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
@ -407,7 +407,7 @@ do
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"
@ -438,7 +438,7 @@ done <<< "$(kdump_read_conf)"
handle_default_dump_target handle_default_dump_target
if [ -n "$extra_modules" ] if [[ -n "$extra_modules" ]]
then then
add_dracut_arg "--add-drivers" "$extra_modules" add_dracut_arg "--add-drivers" "$extra_modules"
fi fi

View File

@ -2,7 +2,7 @@
# Generate an initramfs image that isolates dump capture capability within # Generate an initramfs image that isolates dump capture capability within
# the default initramfs using zz-fadumpinit dracut module. # the default initramfs using zz-fadumpinit dracut module.
if [ -f /etc/sysconfig/kdump ]; then if [[ -f /etc/sysconfig/kdump ]]; then
. /etc/sysconfig/kdump . /etc/sysconfig/kdump
fi fi