1 Star 0 Fork 97

majunqian/systemd

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
fix-journal-file-descriptors-leak-problems.patch 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
From 4f8cec1924bf00532f5350d9a4d7af8e853241fe Mon Sep 17 00:00:00 2001
From: huangkaibin <huangkaibin@huawei.com>
Date: Thu, 28 Jun 2018 20:23:45 +0800
Subject: [PATCH] systemd-journald: Fix journal file descriptors leak problems.
Journal files opened and then be removed by external programs(for example, the journal rotation
of systemd-journald will removed jounal files) before journal directory notify watching is added
will not be closed properly. This patch fix this problem by removing and closing these deleted journal files
after notify watching is added.
---
src/libsystemd/sd-journal/sd-journal.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 5728c53..1238652 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -1584,6 +1584,17 @@ fail:
log_debug_errno(errno, "Failed to enumerate directory %s, ignoring: %m", m->path);
}
+static void remove_nonexistent_journal_files(sd_journal *j) {
+ JournalFile *f = NULL;
+ ORDERED_HASHMAP_FOREACH(f, j->files) {
+ if(f->path && access(f->path, F_OK) < 0) {
+ log_debug("Remove not-existed file from the journal map: %s", f->path);
+ /*Its OK to remove entry from the hashmap although we are iterating on it.*/
+ remove_file_real(j, f);
+ }
+ }
+}
+
static void directory_watch(sd_journal *j, Directory *m, int fd, uint32_t mask) {
int r;
@@ -1612,6 +1623,14 @@ static void directory_watch(sd_journal *j, Directory *m, int fd, uint32_t mask)
(void) inotify_rm_watch(j->inotify_fd, m->wd);
m->wd = -1;
}
+
+ /*
+ * Before event watching, there were some files opened and if some of these opened files were
+ * deleted due to the journal rotation of systemd-jounald, they will become leaking files and will
+ * never be closed until the process exited.
+ * So here we remove these deleted files from the journal after event watching.
+ */
+ remove_nonexistent_journal_files(j);
}
static int add_directory(
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/majunqian/systemd.git
git@gitee.com:majunqian/systemd.git
majunqian
systemd
systemd
master

搜索帮助