Fix truncated fd numbers in -F field output#352
Conversation
When fd numbers >= 10000, fd_to_string() truncates them to fit the
fixed-width FDLEN buffer (e.g., 12345 becomes *345). This truncation
is appropriate for the tabular display but incorrect for -F (field)
output which is designed for machine parsing.
In the -F output path, print numeric fd values directly using
printf("%d") instead of going through fd_to_string(), avoiding
the FDLEN buffer size constraint.
Fixes lsof-org#311
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Re: Cirrus CI failure on FreeBSD 14.3 — tests/LTbasic2 The failing test (LTbasic2) is unrelated to this PR's changes. Here's why:
Could a maintainer re-trigger the Cirrus CI check? If the failure persists, it may be worth tracking as a separate issue. |
This is a known CI failure, possibly due to cirrus CI putting the repo on /tmp where accurate file location is not available for lsof. |
I do not think this is caused by the repository location. CircleCI passes on BSD 15, so the issue seems more specific to the Cirrus CI / FreeBSD 14.3 environment than to the repo being placed under /tmp. |
Summary
-F(field) output mode-Foutput path, numeric fd values are now printed directly viaprintf("%d")instead of going throughfd_to_string(), which truncates to fit the fixed-widthFDLENbufferFixes #311
Details
fd_to_string()formats fd numbers into a buffer of sizeFDLEN(8 bytes). For fd numbers >= 10000, it truncates them with a*prefix (e.g.,12345→*345). This is appropriate for the fixed-width tabularFDcolumn, but incorrect for-Foutput which is designed for machine parsing.Before:
After:
Test plan
-F fdoutput shows full fd number for fds >= 10000-F fdoutput for non-numeric fds (cwd, txt, mem, etc.) is unchanged