Fix incorrect errno short names on FreeBSD/macOS in bwf::Errno#13240
Open
bryancall wants to merge 4 commits into
Open
Fix incorrect errno short names on FreeBSD/macOS in bwf::Errno#13240bryancall wants to merge 4 commits into
bryancall wants to merge 4 commits into
Conversation
The errno short-name lookup indexed a single hardcoded Linux-numbered table by the raw errno value, so on platforms with different numbering it printed the wrong name. A connect timeout (ETIMEDOUT=60) was logged as "ENOSTR" on FreeBSD/macOS, since 60 is ENOSTR only on Linux. Replace the single table with a per-platform table generated from each OS's own <errno.h>, keeping the O(1) direct index. Gaps fall through to "Unknown" and an unsupported platform is a compile error. Fixes: apache#13203
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes swoc::bwf’s short-form errno formatting so that the symbolic name matches the platform’s actual <errno.h> numbering (not Linux’s numbering), addressing misleading log output on FreeBSD/macOS (e.g., ETIMEDOUT incorrectly printed as ENOSTR).
Changes:
- Replaces the single Linux-numbered errno name table with per-platform tables for Linux, macOS, and FreeBSD.
- Adds an
errno_short_name(int)helper used by bothbwf::Errnoand thestd::error_codeformatter. - Preserves long-form errno formatting via
strerror()while correcting short-form symbolic names.
The FreeBSD table was missing EPERM (errno 1), so it formatted as "Unknown". Linux and FreeBSD also picked the ENOTSUP alias over the more common EOPNOTSUPP for that value, which changed existing log output. Prefer the canonical name (EAGAIN/EDEADLK/EOPNOTSUPP) and fill in EPERM. Add a test_bw_format case asserting bwf::Errno prints the platform's own symbolic name for EPERM, ETIMEDOUT, and ECONNREFUSED, guarding against the mislabel this PR fixes.
masaori335
previously approved these changes
Jun 4, 2026
masaori335
left a comment
Contributor
There was a problem hiding this comment.
Having the list per supported platform makes sense to keep it O(1) at lookup.
EL2HLT (Linux 51) and ENOATTR (FreeBSD 87, macOS 93) were left as gaps in the per-platform tables and formatted as "Unknown" even though each is defined in that platform's <errno.h>. Verified the tables by compiling and running against the real headers on Linux, macOS, and FreeBSD 14.3. Restore the std::array the table was before this PR; the raw C array was an unintended downgrade, and size() replaces the sizeof divide in the bounds check. Add a std::error_code formatter test next to the existing bwf::Errno cases, since that path was changed too.
The prior guard asserted ECONNREFUSED, which was never one of the missing entries, so it stayed green even against the broken tables. Add direct ENOATTR (macOS/FreeBSD) and EL2HLT (Linux) assertions, each #ifdef-guarded to its platform, so the suite goes red if those gaps return. Confirmed ENOATTR fails on the pre-fix tables and ENOATTR is undefined on Linux, so the guard is skipped there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in #13203. On FreeBSD (and macOS) Traffic Server logs connection
failures with a misleading errno name, e.g.:
ENOSTR("Not a STREAM", an XSI STREAMS error) has nothing to do with theactual failure, which made these logs confusing to diagnose. The numeric value
[60]is correct; only the symbolic name is wrong.Root cause
swoc::bwf::Errno's short name used a single, hardcoded, Linux-numbered tableindexed directly by the raw errno value:
errno numbering differs across platforms. Value 60 is
ENOSTRon Linux butETIMEDOUTon FreeBSD/macOS (andENOSTRis not defined at all on FreeBSD).So a genuine connection timeout (
ETIMEDOUT, errno 60) was printed asENOSTR. The numbering starts diverging at errno 11 and disagrees on roughly70 of the values shared between Linux and the BSD-derived platforms, so this
was not a one-off.
Fix
Replace the single table with a per-platform table, each generated from that
platform's own
<errno.h>, still looked up by O(1) direct index:#if defined(__linux__)/#elif defined(__APPLE__)/#elif defined(__FreeBSD__)."Unknown".#errorrather than silently wrong names.std::error_codeformatter that shared the old table now routes throughthe same function.
The long form (
{::l}) was already correct because it usesstrerror(); thisonly affects the symbolic short name. (Also drops a stray trailing space in the
old
"E2BIG "entry.)Testing
Compiled and verified on Linux, macOS, and FreeBSD 14.3.
bwf::Errno(60)nowprints:
ENOSTRENOSTR(unchanged; 60 really is ENOSTR there)ENOSTRETIMEDOUTReproduced the original report on FreeBSD 14.3 against the 10.1.0 release: a
connection that timed out and logged
connection_result=ENOSTR [60]nowreports
ETIMEDOUT [60].Fixes #13203