From ae9892db112deeb9f251a59455ac40fae83b0133 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 14 Nov 2023 11:34:55 +0000 Subject: [PATCH] Use closefrom() if available --- ChangeLog | 8 ++++++++ Headers/GNUstepBase/config.h.in | 3 +++ Source/NSTask.m | 4 ++++ configure | 11 +++++++++++ configure.ac | 1 + 5 files changed, 27 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9bdcffe33b..00d9edfb11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-11-14 Richard Frith-Macdonald + + * configure.ac: Add check for closefrom() + * configure: regenerate + * Headers/GNUstepBase/config.h.in: regenerate + * Source/NSTask.m: Use closefrom() to close descriptors in child + process if it is available. + 2023-10-26 Richard Frith-Macdonald * Source/NSISO8601DateFormatter.m: diff --git a/Headers/GNUstepBase/config.h.in b/Headers/GNUstepBase/config.h.in index 7416d509e3..406f2e0686 100644 --- a/Headers/GNUstepBase/config.h.in +++ b/Headers/GNUstepBase/config.h.in @@ -198,6 +198,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_CALLBACK_H +/* Define to 1 if you have the `closefrom' function. */ +#undef HAVE_CLOSEFROM + /* Define to 1 if you have the `ctime' function. */ #undef HAVE_CTIME diff --git a/Source/NSTask.m b/Source/NSTask.m index 792a467755..0c42e13ea1 100644 --- a/Source/NSTask.m +++ b/Source/NSTask.m @@ -1773,10 +1773,14 @@ - (BOOL) launchAndReturnError: (NSError **)error /* * Close any extra descriptors. */ +#if defined(HAVE_CLOSEFROM) + closefrom(3); +#else for (i = 3; i < NOFILE; i++) { (void) close(i); } +#endif if (0 != chdir(path)) { diff --git a/configure b/configure index 0c3cc7654c..e77a4d598a 100755 --- a/configure +++ b/configure @@ -10167,6 +10167,17 @@ _ACEOF fi done +for ac_func in closefrom +do : + ac_fn_c_check_func "$LINENO" "closefrom" "ac_cv_func_closefrom" +if test "x$ac_cv_func_closefrom" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_CLOSEFROM 1 +_ACEOF + +fi +done + if test "x$ac_cv_func_setpgrp" = xyes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether setpgrp takes no argument" >&5 $as_echo_n "checking whether setpgrp takes no argument... " >&6; } diff --git a/configure.ac b/configure.ac index c3d5fa6f7e..57d03731f3 100644 --- a/configure.ac +++ b/configure.ac @@ -2592,6 +2592,7 @@ AC_CHECK_HEADERS(sys/mman.h) # These functions needed by NSTask.m #-------------------------------------------------------------------- AC_CHECK_FUNCS(killpg setpgrp setpgid setsid grantpt) +AC_CHECK_FUNCS(closefrom) if test "x$ac_cv_func_setpgrp" = xyes; then AC_FUNC_SETPGRP fi