Refactor in 57b0864a4577f880bb9f2bdef89868f7fcef96c5 drops all log messages

未关闭 适合新手
#149 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, linux
领域
backend

调研方向

阅读 src/netlog/netlog-journal.c,重点关注 parse_journal_fields 及其调用方 journal_read_input。追踪 JOURNAL_FOREACH_DATA_RETVAL 如何报告迭代结束,以及调用方如何处理返回值。确认成功解析的消息会被保留,错误仍会继续传播。

由索引模型根据 Issue 内容生成。

描述

bug

The refactor in 57b0864a4577f880bb9f2bdef89868f7fcef96c5 (currently unreleased) seems to have a bug that causes it to discard all messages.

parse_journal_fields returns r at the end. r is set by the JOURNAL_FOREACH_DATA_RETVAL macro, which calls sd_journal_enumerate_data. That function indicates iteration done by returning 0.

So on success, parse_journal_fields returns 0.

But its caller, journal_read_input checks for return code 0 and discards the message (returns itself).

I think something like this fixes it:

diff --git a/src/netlog/netlog-journal.c b/src/netlog/netlog-journal.c
index 41dd4d8..ba6a6fb 100644
--- a/src/netlog/netlog-journal.c
+++ b/src/netlog/netlog-journal.c
@@ -127,7 +127,7 @@ static int parse_journal_fields(Manager *m,
                 return 0;
         }
 
-        return r;
+        return r < 0 ? r : 1;
 }
 
 static int parse_syslog_severity(Manager *m, const char *priority, unsigned *sev) {

but beware my line numbers are different as I'm working on adding some features.

主要语言
C
星标
99
派生
35
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

systemd/systemd-netlogd 的其他 Issue

查看 systemd/systemd-netlogd 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。