[glib: 1/2] gspawn: Use close_range() if available to close FDs between fork/exec
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gspawn: Use close_range() if available to close FDs between fork/exec
- Date: Tue, 13 Oct 2020 06:52:11 +0000 (UTC)
commit 9f8ccee65f854443d94ac0dad6e6a164466e7019
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Oct 12 18:10:45 2020 +0100
gspawn: Use close_range() if available to close FDs between fork/exec
It’s landed in kernel 5.9: http://lkml.iu.edu/hypermail/linux/kernel/2008.0/02649.html
Note, this is untested because I currently don’t have kernel 5.9. We can
fix anything up if it breaks once the new syscall is wrapped in glibc.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
glib/gspawn.c | 5 +++++
meson.build | 1 +
2 files changed, 6 insertions(+)
---
diff --git a/glib/gspawn.c b/glib/gspawn.c
index b60073712..af76629f8 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1327,6 +1327,11 @@ safe_closefrom (int lowfd)
* simple wrapper of the fcntl command.
*/
(void) fcntl (lowfd, F_CLOSEM);
+#elif 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 */
+ (void) close_range (lowfd, G_MAXUINT);
#else
(void) safe_fdwalk (close_func, GINT_TO_POINTER (lowfd));
#endif
diff --git a/meson.build b/meson.build
index b27ce9b00..e0b308a25 100644
--- a/meson.build
+++ b/meson.build
@@ -473,6 +473,7 @@ if host_system == 'windows'
endif
functions = [
+ 'close_range',
'endmntent',
'endservent',
'fallocate',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]