1 Star 0 Fork 17

liubuguiii/src-kiran-cc-daemon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0025-fix-timedate-Fix-the-ntp-service-load-order-logic-er.patch 4.09 KB
一键复制 编辑 原始数据 按行查看 历史
From 2952b5d65d8920ab3ee41433399915b0b20b51a2 Mon Sep 17 00:00:00 2001
From: tangjie02 <tangjie02@kylinsec.com.cn>
Date: Thu, 29 Aug 2024 09:58:19 +0800
Subject: [PATCH 25/27] fix(timedate): Fix the ntp service load order logic
error.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 修复ntp服务加载顺序逻辑错误问题,之前的代码加载顺序是随机的
- 去重逻辑有问题,std::unique只会对相邻的元素进行去重
Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
---
plugins/timedate/timedate-manager.cpp | 42 ++++++++++++++++++---------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/plugins/timedate/timedate-manager.cpp b/plugins/timedate/timedate-manager.cpp
index fdd9acc..1a28877 100644
--- a/plugins/timedate/timedate-manager.cpp
+++ b/plugins/timedate/timedate-manager.cpp
@@ -1,14 +1,14 @@
/**
- * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
+ * Copyright (c) 2020 ~ 2021 KylinSec Co., Ltd.
* kiran-cc-daemon is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
- * http://license.coscl.org.cn/MulanPSL2
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- *
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
* Author: tangjie02 <tangjie02@kylinos.com.cn>
*/
@@ -387,7 +387,7 @@ void TimedateManager::init_ntp_units()
this->ntp_unit_name_.clear();
for (auto &ntp_unit : ntp_units)
{
- if (ntp_unit == ntp_units.back())
+ if (ntp_unit == ntp_units.front())
{
this->ntp_unit_name_ = ntp_unit;
continue;
@@ -426,11 +426,21 @@ std::vector<std::string> TimedateManager::get_ntp_units()
{
auto &unit_dir = *iter;
Glib::Dir dir(unit_dir);
+ std::vector<std::string> paths;
for (auto dir_iter = dir.begin(); dir_iter != dir.end(); ++dir_iter)
{
auto entry = *dir_iter;
auto path = fmt::format("{0}/{1}", unit_dir, entry);
+ paths.push_back(path);
+ }
+
+ // 排序确定加载优先级,字母序越大的优先使用
+ std::sort(paths.begin(), paths.end(), std::greater<std::string>());
+
+ for (auto iter = paths.begin(); iter != paths.end(); ++iter)
+ {
+ auto path = *iter;
std::string contents;
try
@@ -460,8 +470,15 @@ std::vector<std::string> TimedateManager::get_ntp_units()
continue;
}
- KLOG_DEBUG_TIMEDATE("Insert ntp unit: %s %s.", line.c_str(), entry.c_str());
- ntp_units.push_back(line);
+ if (std::find(ntp_units.begin(), ntp_units.end(), line) == ntp_units.end())
+ {
+ KLOG_DEBUG_TIMEDATE("Insert ntp unit: %s %s.", line.c_str(), path.c_str());
+ ntp_units.push_back(line);
+ }
+ else
+ {
+ KLOG_DEBUG_TIMEDATE("Ignore duplication ntp unit: %s %s.", line.c_str(), path.c_str());
+ }
}
}
}
@@ -471,9 +488,6 @@ std::vector<std::string> TimedateManager::get_ntp_units()
}
}
- // Remove duplicates.
- auto iter = std::unique(ntp_units.begin(), ntp_units.end());
- ntp_units.erase(iter, ntp_units.end());
return ntp_units;
}
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liubuguiii/src-kiran-cc-daemon.git
git@gitee.com:liubuguiii/src-kiran-cc-daemon.git
liubuguiii
src-kiran-cc-daemon
src-kiran-cc-daemon
master

搜索帮助