From 8bf40e44a06fd5a154cb04975f6fff1933e52425 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 30 Aug 2023 13:34:23 +0200 Subject: [PATCH] misc: add syscall fallback for close_range for musl libc Add fallback for the close_range syscall wrapper. This is needed for musl libc, which currently does not have a close_range wrapper. --- meson.build | 2 ++ src/shared/misc.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/meson.build b/meson.build index 58b7db9af..b7356b9ab 100644 --- a/meson.build +++ b/meson.build @@ -198,6 +198,8 @@ endif if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include ') and \ cc.has_header_symbol('unistd.h', 'CLOSE_RANGE_CLOEXEC', prefix: '#define _GNU_SOURCE') add_project_arguments('-DHAVE_CLOSE_RANGE', language: 'c') +elif cc.has_header('linux/close_range.h') + add_project_arguments('-DHAVE_LINUX_CLOSE_RANGE_H', language: 'c') endif if cc.has_function('strlcpy', prefix: '#define _GNU_SOURCE\n#include ') diff --git a/src/shared/misc.c b/src/shared/misc.c index 4c3884479..5c92a8b16 100644 --- a/src/shared/misc.c +++ b/src/shared/misc.c @@ -24,6 +24,9 @@ #include #include #include +#ifdef HAVE_LINUX_CLOSE_RANGE_H +# include +#endif #include #include #include @@ -31,6 +34,7 @@ #include #include #ifdef __linux__ +# include /* for close_range */ # include #endif #include @@ -511,7 +515,11 @@ static inline int close_range(unsigned int first RC_UNUSED, unsigned int last RC_UNUSED, unsigned int flags RC_UNUSED) { +#ifdef SYS_close_range + return syscall(SYS_close_range, first, last, flags); +#else return -1; +#endif } #endif #ifndef CLOSE_RANGE_CLOEXEC