aboutsummaryrefslogtreecommitdiff
path: root/src/shared/misc.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2023-08-30 13:34:23 +0200
committerWilliam Hubbs <w.d.hubbs@gmail.com>2023-09-12 22:53:12 -0500
commitc4785f1b99bd479926514c48fe0b5489eccfdfaa (patch)
tree92db15925e237bb3fe6b236dfdb13c68d633de12 /src/shared/misc.c
parente447562aaadc96f8f95d6659e4776ce5c1a6c9d6 (diff)
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. Also set errno on errors.
Diffstat (limited to 'src/shared/misc.c')
-rw-r--r--src/shared/misc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/shared/misc.c b/src/shared/misc.c
index 429407d4..28f4e235 100644
--- a/src/shared/misc.c
+++ b/src/shared/misc.c
@@ -24,6 +24,9 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#ifdef HAVE_LINUX_CLOSE_RANGE_H
+# include <linux/close_range.h>
+#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -31,6 +34,7 @@
#include <sys/file.h>
#include <sys/time.h>
#ifdef __linux__
+# include <sys/syscall.h> /* for close_range */
# include <sys/sysinfo.h>
#endif
#include <sys/types.h>
@@ -511,7 +515,12 @@ static inline int close_range(int first RC_UNUSED,
int last RC_UNUSED,
unsigned int flags RC_UNUSED)
{
+#ifdef SYS_close_range
+ return syscall(SYS_close_range, first, last, flags);
+#else
+ errno = ENOSYS;
return -1;
+#endif
}
#endif
#ifndef CLOSE_RANGE_CLOEXEC