mkdumprd: use kdump_get_conf_val to read config values

Simplify the code and cover more corner cases.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-08-04 01:58:04 +08:00
parent 80525aface
commit 075e62252e
1 changed files with 7 additions and 17 deletions

View File

@ -23,7 +23,6 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
conf_file="/etc/kdump.conf"
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
SAVE_PATH=$(get_save_path) SAVE_PATH=$(get_save_path)
OVERRIDE_RESETTABLE=0 OVERRIDE_RESETTABLE=0
@ -312,19 +311,6 @@ handle_default_dump_target()
check_size fs $_target check_size fs $_target
} }
get_override_resettable()
{
local override_resettable
override_resettable=$(grep "^override_resettable" $conf_file)
if [ -n "$override_resettable" ]; then
OVERRIDE_RESETTABLE=$(echo $override_resettable | cut -d' ' -f2)
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then
perror_exit "override_resettable value $OVERRIDE_RESETTABLE is invalid"
fi
fi
}
# $1: function name # $1: function name
for_each_block_target() for_each_block_target()
{ {
@ -363,9 +349,13 @@ is_unresettable()
#return true if resettable #return true if resettable
check_resettable() check_resettable()
{ {
local _ret _target local _ret _target _override_resettable
get_override_resettable _override_resettable=$(kdump_get_conf_val override_resettable)
OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE}
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then
perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid"
fi
for_each_block_target is_unresettable for_each_block_target is_unresettable
_ret=$? _ret=$?
@ -395,7 +385,7 @@ if ! check_crypt; then
fi fi
# firstly get right SSH_KEY_LOCATION # firstly get right SSH_KEY_LOCATION
keyfile=$(awk '/^sshkey/ {print $2}' $conf_file) 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)