summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2022-12-19 13:08:15 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2022-12-19 13:08:15 +0000
commitbebf13d5d62fd8e962a7b55523305b70c60155c0 (patch)
tree16d4656fdf3c3a5115af625d044a1185b034edbf
parentd3a26bb4de281da9775ce2e89a1ac554d4346488 (diff)
parent0ec83bb6507afb3d4e82056fcfde4e6968af7716 (diff)
downloadglib-bebf13d5d62fd8e962a7b55523305b70c60155c0.tar.gz
Merge branch 'close-range-freebsd' into 'main'
gspawn.c: prefer close_range() on FreeBSD if available See merge request GNOME/glib!3144
-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;