-
Notifications
You must be signed in to change notification settings - Fork 1.8k
network: fix strerror_r detection for musl #10804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
network: fix strerror_r detection for musl #10804
Conversation
/home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c: In function ‘net_connect_async’: /home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c:653:17: error: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 653 | str = strerror_r(error, so_error_buf, sizeof(so_error_buf)); | ^ This fix should work perfectly for: glibc systems: Uses str = strerror_r(...) (GNU version) musl systems: Uses ret = strerror_r(...); if (ret == 0) str = so_error_buf; (POSIX version) Other libc implementations: Defaults to POSIX behavior Fix is similar to janet-lang/janet@a5d6b22. Signed-off-by: Thomas Devoogdt <[email protected]>
WalkthroughThe change updates error-string handling in net_connect_async when a TCP connection fails. It replaces POSIX/XOPEN conditionals with GLIBC-specific handling and distinct non-GLIBC logic, adjusting how strerror_r is invoked and how its result is used in the final log message. No public interfaces were changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Net as net_connect_async
participant LibC as libc (strerror_r)
participant Log as logger
Caller->>Net: initiate TCP connect (async)
Net-->>Caller: connection fails (SO\_ERROR set)
rect rgb(240,248,255)
Note over Net: Derive error string
alt GLIBC build
Net->>LibC: strerror_r(error, buf, sizeof(buf)) [returns char*]
LibC-->>Net: str (pointer)
Net->>Log: flb_warn("...: %s", str)
else non-GLIBC build
Net->>LibC: ret = strerror_r(error, buf, sizeof(buf)) [int]
alt ret == 0
Net->>Log: flb_warn("...: %s", buf)
else ret != 0
Net->>Log: flb_errno()
Net-->>Caller: return -1
end
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/flb_network.c (3)
641-643
: Tighten feature test to avoid false positives (e.g., uClibc)Prefer guarding the GNU variant with both glibc and _GNU_SOURCE to avoid mis-detecting libcs that may define GLIBC compatibility macros but don’t provide the GNU strerror_r semantics.
Apply:
-#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(_GNU_SOURCE) str = strerror_r(error, so_error_buf, sizeof(so_error_buf)); #elsePlease verify builds on: glibc (Debian/Ubuntu), musl (Alpine), and, if relevant, uClibc/Bionic.
644-651
: Make POSIX branch failure deterministic and preserve context in logsOn POSIX strerror_r failures, ret holds the failure code but errno may not be set; calling flb_errno() can log a stale errno and returns early, dropping the host/port context. Fall back to a formatted message instead and proceed to the flb_error() line.
Apply:
- ret = strerror_r(error, so_error_buf, sizeof(so_error_buf)); - if (ret == 0) { - str = so_error_buf; - } - else { - flb_errno(); - return -1; - } + ret = strerror_r(error, so_error_buf, sizeof(so_error_buf)); + if (ret == 0) { + str = so_error_buf; + } + else { + snprintf(so_error_buf, sizeof(so_error_buf), + "strerror_r(%d) failed: %d", error, ret); + str = so_error_buf; + }
519-520
: Minor: make error string pointer constWe don’t mutate the buffer; prefer const for clarity and to accept static strings returned by the GNU variant.
Change:
- char *str;
To:- const char *str;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/flb_network.c
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
- GitHub Check: PR - fuzzing test
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
- GitHub Check: pr-compile-centos-7
🔇 Additional comments (1)
src/flb_network.c (1)
641-643
: LGTM: correct GNU strerror_r usage on glibcUsing the char*-returning GNU variant behind a glibc guard fixes the musl build error and is correct on glibc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks attractive. Excellent work!
This fix should work perfectly for:
Fix is similar to janet-lang/janet@a5d6b22.
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor