Add a helper `kdump_get_conf_val` to replace get_option_value.
It can help cover more corner cases in the code, like when there are multiple spaces in config file value, currently kdumpctl will fail to retrive some config value.
And this uses "sed group command" and "sed hold buffer", make it much faster than previous `grep <config> | tail -1`.
Signed-off-by: Kairui Song kasong@redhat.com --- dracut-module-setup.sh | 4 ++-- kdump-lib.sh | 20 +++++++++----------- kdumpctl | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ff9f7fee..53abdc75 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -938,7 +938,7 @@ get_generic_fence_kdump_nodes() { local filtered local nodes
- nodes=$(get_option_value "fence_kdump_nodes") + nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in ${nodes}; do # Skip its own node name if is_localhost $node; then @@ -999,7 +999,7 @@ kdump_install_random_seed() { }
kdump_install_systemd_conf() { - local failure_action=$(get_option_value "failure_action") + local failure_action=$(kdump_get_conf_val "failure_action")
# Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. diff --git a/kdump-lib.sh b/kdump-lib.sh index 0970261e..c74bdacd 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -76,11 +76,6 @@ is_fs_dump_target() egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf }
-strip_comments() -{ - echo $@ | sed -e 's/(.*)#.*/\1/' -} - # Read kdump config in well formated style kdump_read_conf() { @@ -89,6 +84,15 @@ kdump_read_conf() [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/(\S+)\s*(.*)/\1 \2/p" $KDUMP_CONFIG_FILE }
+# kdump_get_conf_val <config name> +# retrieves config value defined in kdump.conf +kdump_get_conf_val() { + # For lines matching "^\s*$1\s+", remove matched part (config name including space), + # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && \ + sed -n -e "/^\s*$1\s+/{s/^\s*$1\s+//;s/#.*//;s/\s*$//;h};${x;p}" $KDUMP_CONFIG_FILE +} + # Check if fence kdump is configured in Pacemaker cluster is_pcs_fence_kdump() { @@ -322,12 +326,6 @@ get_kdump_mntpoint_from_target() echo $_mntpoint | tr -s "/" }
-# get_option_value <option_name> -# retrieves value of option defined in kdump.conf -get_option_value() { - strip_comments `grep "^$1[[:space:]]+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` -} - kdump_get_persistent_dev() { local dev="${1//"/}"
diff --git a/kdumpctl b/kdumpctl index 5d9420da..db3a3015 100755 --- a/kdumpctl +++ b/kdumpctl @@ -961,7 +961,7 @@ check_fence_kdump_config() { local hostname=`hostname` local ipaddrs=`hostname -I` - local nodes=$(get_option_value "fence_kdump_nodes") + local nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do if [ "$node" = "$hostname" ]; then