-
Notifications
You must be signed in to change notification settings - Fork 1.8k
in_kmsg: fix /dev/kmsg parsing #10807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughReworks kmsg input parsing in Changes
Sequence Diagram(s)sequenceDiagram
participant Kernel as Kernel log line
participant Parser as in_kmsg.c Parser
participant Buffer as Buffer/State
Kernel->>Parser: raw kmsg line
Parser->>Parser: strtoul(priority) -> val
alt priority parse error (no digits / ERANGE / bad delimiter)
Parser-->>Buffer: fail (ctx->buffer_id--)
Parser->>Kernel: discard line
else valid priority
Parser->>Parser: FLB_KLOG_PRI(val)
Parser->>Parser: strtoull(sequence) -> seq_val
alt sequence parse error
Parser-->>Buffer: fail (ctx->buffer_id--)
Parser->>Kernel: discard line
else valid sequence
Parser->>Parser: strtoull(timestamp) -> t_val
alt timestamp parse error
Parser-->>Buffer: fail (ctx->buffer_id--)
Parser->>Kernel: discard line
else valid timestamp
Parser->>Parser: tv_sec = t_val / KMSG_USEC_PER_SEC
Parser->>Parser: tv_usec = t_val % KMSG_USEC_PER_SEC
Parser->>Buffer: commit parsed record
end
end
end
note right of Parser: strict consumption & delimiter checks added
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
plugins/in_kmsg/in_kmsg.c (1)
179-180
: tv_usec calc fix is correct; consider simpler modulo form and constant.Functionally correct and 64-bit safe. For readability/consistency with KMSG_USEC_PER_SEC, modulo is clearer.
Apply:
- tv.tv_sec = val/1000000; - tv.tv_usec = val - ((uint64_t)tv.tv_sec * 1000000); + tv.tv_sec = val / KMSG_USEC_PER_SEC; + tv.tv_usec = val % KMSG_USEC_PER_SEC;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
plugins/in_kmsg/in_kmsg.c
(3 hunks)
🔇 Additional comments (3)
plugins/in_kmsg/in_kmsg.c (3)
125-130
: Good switch to unsigned parsing with correct overflow guard.Using strtoul for priority with the ULONG_MAX/ERANGE check is correct for an unsigned field.
137-137
: Priority derivation from unsigned value looks right.Mapping via FLB_KLOG_PRI(val) after unsigned parsing aligns with the field semantics.
157-162
: Nice: strict sequence parsing with delimiter check.The end != p and immediate ',' enforcement eliminates ambiguous inputs.
Also applies to: 164-165
* use strtoul for priority since it is unsigned * check for overflow correctly by comparing against ULONG_MAX * fail if no digits were consumed or next character is not comma * calculate tv.tv_usec correctly in case tv.tv_sec 32-bit * remove redundant errno = 0 added in 3254b9a * remove erroneous time.h added with 72d9dc8 Signed-off-by: Erik Karlsson <[email protected]>
Pushed a minor change which uses |
Output from test:
Test with valgrind:
|
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit
Bug Fixes
Refactor
Chores