kdumpctl: use kdump_get_conf_val to read config values

Also fixed kdumpctl, use `awk` instead of `cut` to read
core_collector's executable name correctly when its arguments
are not seperated by space.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-08-03 22:50:02 +08:00
parent ab1ef78aa2
commit 01613b7211

View File

@ -339,8 +339,8 @@ check_files_modified()
#also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled.
modified_files=$(get_pcs_cluster_modified_files) modified_files=$(get_pcs_cluster_modified_files)
EXTRA_BINS=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2` EXTRA_BINS=$(kdump_get_conf_val kdump_post)
CHECK_FILES=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\ -f2` 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
@ -357,17 +357,17 @@ check_files_modified()
done done
fi fi
HOOKS="$HOOKS $POST_FILES $PRE_FILES" HOOKS="$HOOKS $POST_FILES $PRE_FILES"
CORE_COLLECTOR=`grep ^core_collector $KDUMP_CONFIG_FILE | cut -d\ -f2` 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=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\ -f2-` CHECK_FILES=$(kdump_get_conf_val extra_bins)
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR"
[[ -e /etc/fstab ]] && files="$files /etc/fstab" [[ -e /etc/fstab ]] && files="$files /etc/fstab"
# Check for any updated extra module # Check for any updated extra module
EXTRA_MODULES="$(grep ^extra_modules $KDUMP_CONFIG_FILE | sed 's/^extra_modules\s*//')" 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"
@ -555,8 +555,7 @@ check_system_modified()
check_rebuild() check_rebuild()
{ {
local capture_capable_initrd="1" local capture_capable_initrd="1"
local _force_rebuild force_rebuild="0" local force_rebuild force_no_rebuild
local _force_no_rebuild force_no_rebuild="0"
local ret system_modified="0" local ret system_modified="0"
setup_initrd setup_initrd
@ -565,22 +564,18 @@ check_rebuild()
return 1 return 1
fi fi
_force_no_rebuild=`grep ^force_no_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` force_no_rebuild=$(kdump_get_conf_val force_no_rebuild)
if [ $? -eq 0 ]; then force_no_rebuild=${force_no_rebuild:-0}
force_no_rebuild=`echo $_force_no_rebuild | cut -d' ' -f2` 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 fi
_force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` force_rebuild=$(kdump_get_conf_val force_rebuild)
if [ $? -eq 0 ]; then force_rebuild=${force_rebuild:-0}
force_rebuild=`echo $_force_rebuild | cut -d' ' -f2` 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 fi
if [[ "$force_no_rebuild" == "1" && "$force_rebuild" == "1" ]]; then if [[ "$force_no_rebuild" == "1" && "$force_rebuild" == "1" ]]; then
@ -867,7 +862,7 @@ save_raw()
local kdump_dir local kdump_dir
local raw_target local raw_target
raw_target=$(awk '$1 ~ /^raw$/ { print $2; }' $KDUMP_CONFIG_FILE) 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"
@ -878,7 +873,7 @@ save_raw()
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
kdump_dir=`grep ^path $KDUMP_CONFIG_FILE | cut -d' ' -f2-` 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
@ -1018,8 +1013,8 @@ check_failure_action_config()
local failure_action local failure_action
local option="failure_action" local option="failure_action"
default_option=$(awk '$1 ~ /^default$/ {print $2;}' $KDUMP_CONFIG_FILE) default_option=$(kdump_get_conf_val default)
failure_action=$(awk '$1 ~ /^failure_action$/ {print $2;}' $KDUMP_CONFIG_FILE) failure_action=$(kdump_get_conf_val failure_action)
if [ -z "$failure_action" -a -z "$default_option" ]; then if [ -z "$failure_action" -a -z "$default_option" ]; then
return 0 return 0
@ -1047,7 +1042,7 @@ check_final_action_config()
{ {
local final_action local final_action
final_action=$(awk '$1 ~ /^final_action$/ {print $2;}' $KDUMP_CONFIG_FILE) final_action=$(kdump_get_conf_val final_action)
if [ -z "$final_action" ]; then if [ -z "$final_action" ]; then
return 0 return 0
else else