[PATCH v2 0/2] Build fixes for musl, glibc < 2.34
v2: Take care of cppcheck warning in 2/2 Stefano Brivio (2): udp_flow: Add missing unistd.h include for close() util: Provide own version of close_range(), and no-op fallback udp_flow.c | 1 + util.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) -- 2.43.0
For some reason, this is reported only with musl, and older glibc
versions (2.31, at least).
Signed-off-by: Stefano Brivio
musl, as of 1.2.5, and glibc < 2.34 don't ship a (trivial)
close_range() implementation. This will probably be added to musl
soon, by the way:
https://www.openwall.com/lists/musl/2024/08/01/9
Add a weakly-aliased implementation, if it's supported by the kernel.
If it's not supported (< 5.9), use a no-op fallback. Looping over 2^31
file descriptors calling close() on them is probably not a good idea.
Reported-by: lemmi
On Tue, Aug 20, 2024 at 11:58:53PM +0200, Stefano Brivio wrote:
musl, as of 1.2.5, and glibc < 2.34 don't ship a (trivial) close_range() implementation. This will probably be added to musl soon, by the way: https://www.openwall.com/lists/musl/2024/08/01/9
Add a weakly-aliased implementation, if it's supported by the kernel. If it's not supported (< 5.9), use a no-op fallback. Looping over 2^31 file descriptors calling close() on them is probably not a good idea.
Reported-by: lemmi
Signed-off-by: Stefano Brivio
Reviewed-by: David Gibson
--- util.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/util.h b/util.h index cb4d181..9c95dcd 100644 --- a/util.h +++ b/util.h @@ -14,6 +14,9 @@ #include
#include #include +#include +#include +#include #include "log.h"
@@ -160,6 +163,25 @@ struct ctx;
/* cppcheck-suppress funcArgNamesDifferent */ __attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i); } + +#ifdef CLOSE_RANGE_UNSHARE /* Linux kernel >= 5.9 */ +/* glibc < 2.34 and musl as of 1.2.5 need these */ +#ifndef SYS_close_range +#define SYS_close_range 436 +#endif +__attribute__ ((weak)) +/* cppcheck-suppress funcArgNamesDifferent */ +int close_range(unsigned int first, unsigned int last, int flags) { + return syscall(SYS_close_range, first, last, flags); +} +#else +/* No reasonable fallback option */ +/* cppcheck-suppress funcArgNamesDifferent */ +int close_range(unsigned int first, unsigned int last, int flags) { + return 0; +} +#endif + int sock_l4_sa(const struct ctx *c, enum epoll_type type, const void *sa, socklen_t sl, const char *ifname, bool v6only, uint32_t data);
-- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
participants (2)
-
David Gibson
-
Stefano Brivio