Skip to content

lscpu: handle incomplete sysfs without panicking - #720

Open
tuxnode wants to merge 2 commits into
uutils:mainfrom
tuxnode:lscpu/no-panic
Open

tuxnode wants to merge 2 commits into
uutils:mainfrom
tuxnode:lscpu/no-panic

Conversation

@tuxnode

@tuxnode tuxnode commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

#717

lscpu still panics when sysfs is incomplete, for example when cache files or topology files are missing (#494). Treat missing or malformed data as partial information instead.

Changes

  • Fall back to an unknown package ID (-1) when physical_package_id is missing.
  • Treat a CPU without core_id as its own core.
  • Skip cache entries with missing/invalid type, level, size or shared_cpu_map.
  • Make CacheSize::parse and parse_cpu_list fallible instead of panicking.
  • Handle non-UTF-8 vulnerability filenames without slicing.

Tests

Added fixture-based tests for:

  • missing cache directory
  • missing/invalid cache metadata
  • unknown cache type
  • missing topology files
  • invalid CPU list

@tuxnode
tuxnode force-pushed the lscpu/no-panic branch 2 times, most recently from 9741c38 to ce2f8c6 Compare November 28, 2026 08:31
Comment thread src/uu/lscpu/src/sysfs.rs Resolved
@tuxnode

tuxnode commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Done in 7f746a3

@tuxnode
tuxnode requested a review from sylvestre November 29, 2026 08:23
@tuxnode

tuxnode commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

It seems that there is a problem with the software source of CI 👀

Treat missing or malformed topology and cache metadata as partial data instead of unwrapping or panicking. Skip unreadable cache entries, parse CPU lists and cache sizes fallibly, and add fixture-based tests for missing cache directories, cache metadata, topology files and invalid CPU lists.
Address review feedback: core_count() deduplicated core_id globally, so a
CPU with a missing core_id (which fell back to its CPU index) could be merged
with an unrelated core that had the same numeric id, undercounting cores.

Store core_id as Option<usize>, count each CPU without one as its own core,
and key known cores by (package, core) since core_id is only unique within a
package. Add a test where only one CPU is missing core_id.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants