On Wed, 6 Nov 2024 17:54:16 +1100
David Gibson <david(a)gibson.dropbear.id.au> wrote:
util.h has some #ifdefs and weak definitions to
handle compatibility with
various kernel versions. Move this to linux_dep.h which handles several
other similar cases.
Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
linux_dep.h | 20 ++++++++++++++++++++
util.h | 19 -------------------
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/linux_dep.h b/linux_dep.h
index eae9c3c..3a41e42 100644
--- a/linux_dep.h
+++ b/linux_dep.h
@@ -125,4 +125,24 @@ struct tcp_info_linux {
#define FALLOC_FL_COLLAPSE_RANGE 0x08
#endif
+#include <linux/close_range.h>
+
+#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
+
#endif /* LINUX_DEP_H */
diff --git a/util.h b/util.h
index 2858b10..fdc3af8 100644
--- a/util.h
+++ b/util.h
@@ -17,7 +17,6 @@
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/syscall.h>
-#include <linux/close_range.h>
#include "log.h"
@@ -158,24 +157,6 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size,
int flags,
struct ctx;
-#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
-
This breaks the build on Alpine as well:
util.c: In function 'close_open_files':
util.c:729:22: error: implicit declaration of function 'close_range'; did you
mean 'SYS_close_range'? [-Wimplicit-function-declaration]
729 | rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE);
| ^~~~~~~~~~~
| SYS_close_range
util.c:729:58: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this
function)
729 | rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE);
| ^~~~~~~~~~~~~~~~~~~
and is fixed by including "linux_dep.h" from util.c.
Oops again, adjusted.
--
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.