systemd: fix SystemdMeter parsing when falling back to systemctl show#2037
Conversation
When htop falls back to parsing `systemctl show` output via fgets/strtoul, the trailing newline preserved by fgets causes strtoul's endptr to point to '\n' instead of '\0'. The value check only tested for '\0', so all numeric fields stayed at INVALID_VALUE, displaying as "(?/? failed) (?/? jobs)". Accept both '\n' and '\0' as valid end-of-value terminators. Fixes htop-dev#1982
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChangesThis change adjusts numeric parsing validation in Assessment against linked issues
Assessment against linked issues: Out-of-scope changes No out-of-scope changes found. Poem
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. Comment |
Summary
(?/? failed) (?/? jobs)when htop falls back tosystemctl showfor parsing systemd stateRoot Cause
fgets()preserves trailing newlines in the buffer, sostrtoul()leavesendptrpointing to'\n'instead of'\0'. The validation check*endptr == '\0'fails, causing all numeric fields to remain atINVALID_VALUE.This only affects the
systemctl showfallback path (used whensd_bus_open_userfails, e.g. under file capabilities). Thesd_buspath is unaffected.Note:
SystemState=was already handled correctly — it explicitly strips the newline withstrchr(lineBuffer, '\n').Changes
linux/SystemdMeter.c'\n'as valid end-of-value terminator in addition to'\0'(4 occurrences)Test Plan
--enable-werrorsd_bus_open_userfails (e.g. Gentoo with filecaps), or test by temporarily forcingupdateViaExecpathFixes #1982