!30 Incorrect processing of empty files for resolv.conf

From: @kylinos-zhangqiang 
Reviewed-by: @gebidelidaye 
Signed-off-by: @gebidelidaye
This commit is contained in:
openeuler-ci-bot 2022-11-09 07:01:58 +00:00 committed by Gitee
commit 3b6f40c8e1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,62 @@
From 18a9b144be17afca1a5bdb9d1142e6dbf201d8a7 Mon Sep 17 00:00:00 2001
From: zhangqiang <zhangqiang@kylinos.cn>
Date: Mon, 7 Nov 2022 07:14:11 +0800
Subject: [PATCH] Incorrect processing of empty files for resolv.conf When
resolv.conf is empty or does not exist,ifup-post backup files that do not
match expectations.
---
network-scripts/ifup | 2 ++
network-scripts/network-functions | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/network-scripts/ifup b/network-scripts/ifup
index a053077..8871526 100755
--- a/network-scripts/ifup
+++ b/network-scripts/ifup
@@ -50,6 +50,8 @@ if [ ${UID} != 0 ]; then
exit 1
fi
+init_resolv_conf
+
source_config
if ! is_true ${DEPRECATION_WARNING_ISSUED}; then
diff --git a/network-scripts/network-functions b/network-scripts/network-functions
index eed3c91..83e4bea 100644
--- a/network-scripts/network-functions
+++ b/network-scripts/network-functions
@@ -633,6 +633,29 @@ is_bonding_device ()
[ -f "/sys/class/net/$1/bonding/slaves" ]
}
+# Initialize /etc/resolv.conf when the network service starts
+init_resolv_conf ()
+{
+ title="# Generated by network"
+ if [ ! -f /etc/resolv.conf ];then
+ echo ${title} > /etc/resolv.conf
+ return 0
+ fi
+ #If the file exists and the content is empty or there are empty lines, the ifup-post condition will be judged wrongly,
+ #and the backup process will be started. Add a comment at the first line here to solve the problem
+ if ! grep -E -q "${title}" /etc/resolv.conf;then
+ if tmp_file=$(mktemp);then
+ echo ${title} > ${tmp_file}
+ cat /etc/resolv.conf >> ${tmp_file}
+ cp -rf ${tmp_file} /etc/resolv.conf
+ /usr/bin/logger -p local7.notice -t "NET" -i "$0 : updated ${title} to /etc/resolv.conf"
+ rm -rf ${tmp_file}
+ else
+ /usr/bin/logger -p local7.err -t "NET" -i "$0 : /etc/resolv.conf was not updated ${title}: failed to create temporary file"
+ fi
+ fi
+}
+
# Invoke this when /etc/resolv.conf has changed:
change_resolv_conf ()
{
--
2.27.0

View File

@ -20,7 +20,7 @@ Requires: gawk \
Name: initscripts Name: initscripts
Summary: Basic support for legacy System V init scripts Summary: Basic support for legacy System V init scripts
Version: 10.17 Version: 10.17
Release: 1 Release: 2
License: GPLv2 License: GPLv2
@ -92,6 +92,7 @@ Patch9004: bugfix-restart-network-warning.patch
Patch9005: new-network-fork-to-start-dhcp.patch Patch9005: new-network-fork-to-start-dhcp.patch
Patch9006: exec-udevadm-settle-when-network-start.patch Patch9006: exec-udevadm-settle-when-network-start.patch
Patch9007: remove-rename_device_lock-when-process-does-not-exis.patch Patch9007: remove-rename_device_lock-when-process-does-not-exis.patch
Patch9008: bugfix-Incorrect-processing-of-empty-files-for-resolv.conf.patch
%description %description
This package provides basic support for legacy System V init scripts, and some This package provides basic support for legacy System V init scripts, and some
@ -388,6 +389,12 @@ fi
# ============================================================================= # =============================================================================
%changelog %changelog
* Mon Nov 07 2022 zhangqiang <zhangqiang@kylinos.cn> - 10.17-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Incorrect processing of empty files for resolv.conf
* Fri Oct 14 2022 gaihuiying <eaglegai@163.com> - 10.17-1 * Fri Oct 14 2022 gaihuiying <eaglegai@163.com> - 10.17-1
- Type:requirement - Type:requirement
- ID:NA - ID:NA