Skip to content

Commit bab8ad5

Browse files
committed
Address review: fix EPERM/EOPNOTSUPP entries, add errno name test
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.
1 parent 7f7ce3f commit bab8ad5

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

lib/swoc/src/bw_format.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static constexpr std::string_view ERRNO_NAMES[] = {
763763
/* 64 */ "ENONET", "ENOPKG", "EREMOTE", "ENOLINK", "EADV", "ESRMNT", "ECOMM", "EPROTO",
764764
/* 72 */ "EMULTIHOP", "EDOTDOT", "EBADMSG", "EOVERFLOW", "ENOTUNIQ", "EBADFD", "EREMCHG", "ELIBACC",
765765
/* 80 */ "ELIBBAD", "ELIBSCN", "ELIBMAX", "ELIBEXEC", "EILSEQ", "ERESTART", "ESTRPIPE", "EUSERS",
766-
/* 88 */ "ENOTSOCK", "EDESTADDRREQ", "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT", "EPROTONOSUPPORT", "ESOCKTNOSUPPORT", "ENOTSUP",
766+
/* 88 */ "ENOTSOCK", "EDESTADDRREQ", "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT", "EPROTONOSUPPORT", "ESOCKTNOSUPPORT", "EOPNOTSUPP",
767767
/* 96 */ "EPFNOSUPPORT", "EAFNOSUPPORT", "EADDRINUSE", "EADDRNOTAVAIL", "ENETDOWN", "ENETUNREACH", "ENETRESET", "ECONNABORTED",
768768
/* 104 */ "ECONNRESET", "ENOBUFS", "EISCONN", "ENOTCONN", "ESHUTDOWN", "ETOOMANYREFS", "ETIMEDOUT", "ECONNREFUSED",
769769
/* 112 */ "EHOSTDOWN", "EHOSTUNREACH", "EALREADY", "EINPROGRESS", "ESTALE", "EUCLEAN", "ENOTNAM", "ENAVAIL",
@@ -789,12 +789,12 @@ static constexpr std::string_view ERRNO_NAMES[] = {
789789
};
790790
#elif defined(__FreeBSD__)
791791
static constexpr std::string_view ERRNO_NAMES[] = {
792-
/* 0 */ "SUCCESS", "", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
792+
/* 0 */ "SUCCESS", "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
793793
/* 8 */ "ENOEXEC", "EBADF", "ECHILD", "EDEADLK", "ENOMEM", "EACCES", "EFAULT", "ENOTBLK",
794794
/* 16 */ "EBUSY", "EEXIST", "EXDEV", "ENODEV", "ENOTDIR", "EISDIR", "EINVAL", "ENFILE",
795795
/* 24 */ "EMFILE", "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE", "EROFS", "EMLINK",
796796
/* 32 */ "EPIPE", "EDOM", "ERANGE", "EAGAIN", "EINPROGRESS", "EALREADY", "ENOTSOCK", "EDESTADDRREQ",
797-
/* 40 */ "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT", "EPROTONOSUPPORT", "ESOCKTNOSUPPORT", "ENOTSUP", "EPFNOSUPPORT", "EAFNOSUPPORT",
797+
/* 40 */ "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT", "EPROTONOSUPPORT", "ESOCKTNOSUPPORT", "EOPNOTSUPP", "EPFNOSUPPORT", "EAFNOSUPPORT",
798798
/* 48 */ "EADDRINUSE", "EADDRNOTAVAIL", "ENETDOWN", "ENETUNREACH", "ENETRESET", "ECONNABORTED", "ECONNRESET", "ENOBUFS",
799799
/* 56 */ "EISCONN", "ENOTCONN", "ESHUTDOWN", "ETOOMANYREFS", "ETIMEDOUT", "ECONNREFUSED", "ELOOP", "ENAMETOOLONG",
800800
/* 64 */ "EHOSTDOWN", "EHOSTUNREACH", "ENOTEMPTY", "EPROCLIM", "EUSERS", "EDQUOT", "ESTALE", "EREMOTE",

lib/swoc/unit_tests/test_bw_format.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <iostream>
99
#include <variant>
1010
#include <cmath>
11+
#include <cerrno>
1112

1213
#include <netinet/in.h>
1314

@@ -545,6 +546,18 @@ TEST_CASE("bwstring std formats", "[libswoc][bwprint]") {
545546
w.clear().print("{::l}", swoc::bwf::Errno(13));
546547
REQUIRE(w.view() == "Permission denied [13]"sv);
547548

549+
// The symbolic short name must come from the running platform's <errno.h>,
550+
// not a fixed Linux-numbered table. Regression guard for the FreeBSD/macOS
551+
// mislabel where ETIMEDOUT (errno 60 on those platforms) printed as "ENOSTR"
552+
// (apache/trafficserver#13203). Use the macros so each platform checks its
553+
// own numbering.
554+
w.clear().print("{:s:s}", swoc::bwf::Errno(EPERM));
555+
REQUIRE(w.view() == "EPERM"sv);
556+
w.clear().print("{:s:s}", swoc::bwf::Errno(ETIMEDOUT));
557+
REQUIRE(w.view() == "ETIMEDOUT"sv);
558+
w.clear().print("{:s:s}", swoc::bwf::Errno(ECONNREFUSED));
559+
REQUIRE(w.view() == "ECONNREFUSED"sv);
560+
548561
time_t t = 1528484137;
549562
// default is GMT
550563
w.clear().print("{} is {}", t, swoc::bwf::Date(t));

0 commit comments

Comments
 (0)