summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Richardson <alexander.richardson@cl.cam.ac.uk>2022-12-19 13:08:13 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2022-12-19 13:08:13 +0000
commit0ec83bb6507afb3d4e82056fcfde4e6968af7716 (patch)
treea18c59f66fc454ed50a76c73f994291ab5cdbdd6
parent953f4fc25f4e6eb70695df5d7a38b65c8839c44b (diff)
downloadglib-0ec83bb6507afb3d4e82056fcfde4e6968af7716.tar.gz
gspawn.c: prefer close_range() on FreeBSD if available
-rw-r--r--glib/gspawn.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/glib/gspawn.c b/glib/gspawn.c
index 298df314f..bca37da3a 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1618,6 +1618,18 @@ safe_closefrom (int lowfd)
{
int ret;
+#if defined(HAVE_CLOSE_RANGE)
+ /* close_range() is available in Linux since kernel 5.9, and on FreeBSD at
+ * around the same time. It was designed for use in async-signal-safe
+ * situations: https://bugs.python.org/issue38061
+ *
+ * Handle ENOSYS in case it’s supported in libc but not the kernel; if so,
+ * fall back to safe_fdwalk(). */
+ ret = close_range (lowfd, G_MAXUINT, 0);
+ if (ret == 0 || errno != ENOSYS)
+ return ret;
+#endif /* HAVE_CLOSE_RANGE */
+
#if defined(__FreeBSD__) || defined(__OpenBSD__) || \
(defined(__sun__) && defined(F_CLOSEFROM))
/* Use closefrom function provided by the system if it is known to be
@@ -1649,18 +1661,6 @@ safe_closefrom (int lowfd)
*/
return fcntl (lowfd, F_CLOSEM);
#else
-
-#if defined(HAVE_CLOSE_RANGE)
- /* close_range() is available in Linux since kernel 5.9, and on FreeBSD at
- * around the same time. It was designed for use in async-signal-safe
- * situations: https://bugs.python.org/issue38061
- *
- * Handle ENOSYS in case it’s supported in libc but not the kernel; if so,
- * fall back to safe_fdwalk(). */
- ret = close_range (lowfd, G_MAXUINT, 0);
- if (ret == 0 || errno != ENOSYS)
- return ret;
-#endif /* HAVE_CLOSE_RANGE */
ret = safe_fdwalk (close_func_with_invalid_fds, GINT_TO_POINTER (lowfd));
return ret;