diff --git a/meson.build b/meson.build index ec970494f..fea864085 100644 --- a/meson.build +++ b/meson.build @@ -197,6 +197,8 @@ endif if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include ') 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 429407d42..d2dbb2256 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,17 @@ static inline int close_range(int first RC_UNUSED, int last RC_UNUSED, unsigned int flags RC_UNUSED) { +#ifdef SYS_close_range + int r = syscall(SYS_close_range, first, last, flags); + if (r < 0) { + errno = -r; + r = -1; + } + return r; +#else + errno = ENOSYS; return -1; +#endif } #endif #ifndef CLOSE_RANGE_CLOEXEC