Current implementation of kdump_setup_dns() get the dns
from interface's ifcfg file first, then parse those in
"/etc/resolv.conf". For example, DNS1 in ifcfg file along
with dhcp, the final dns(/etc/resolv.conf) in 1st system
will be like(dhcp first, then ifcfg file appending end):
dhcp dns1
dhcp dns2
dhcp dns3
DNS1 in ifcfg
After parsing, the dns(/etc/cmdline.d/42dns.conf) in kdump
system will be like:
DNS1 in ifcfg
dhcp dns1
dhcp dns2
dhcp dns3
DNS1 in ifcfg
There are two issues by doing this:
1) The dns sequence is different from that in 1st system.
2) There are some duplicated items.
NOTE: kdump_setup_dns() meant to avoid the duplication,
but the original shell command is actually disfunctional:
"[ ! $(cat $_dnsfile | grep -q $_dns) ]" (always true)
Fix the issues by firstly parsing "/etc/resolv.conf", then
parsing ifcfg file, finally delete the duplicated items.
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
dracut-module-setup.sh | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 350864e..b7763f7 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -68,14 +68,6 @@ kdump_setup_dns() {
local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
local ifcfg_file
- ifcfg_file=$(get_ifcfg_filename $1)
- if [ -f "${ifcfg_file}" ]; then
- . ${ifcfg_file}
- fi
-
- [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile"
- [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
-
while read content;
do
_nameserver=$(echo $content | grep ^nameserver)
@@ -84,10 +76,23 @@ kdump_setup_dns() {
_dns=$(echo $_nameserver | cut -d' ' -f2)
[ -z "$_dns" ] && continue
- if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then
- echo "nameserver=$_dns" >> "$_dnsfile"
- fi
+ echo "nameserver=$_dns" >> "$_dnsfile"
done < "/etc/resolv.conf"
+
+ unset DNS1 DNS2
+ ifcfg_file=$(get_ifcfg_filename $1)
+ if [ -f "${ifcfg_file}" ]; then
+ . ${ifcfg_file}
+ fi
+
+ [ -n "$DNS1" ] && echo "nameserver=$DNS1" >> "$_dnsfile"
+ [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
+
+ # Delete duplicated lines
+ if [ -f "$_dnsfile" ]; then
+ awk '!a[$0]++' $_dnsfile > $_dnsfile.tmp
+ mv -f $_dnsfile.tmp $_dnsfile
+ fi
}
#$1: netdev name
--
1.8.3.1