Use closefrom() if available

This commit is contained in:
rfm 2023-11-14 11:34:55 +00:00
parent 15ff083a9a
commit ae9892db11
5 changed files with 27 additions and 0 deletions

View file

@ -1,3 +1,11 @@
2023-11-14 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org>
* Source/NSISO8601DateFormatter.m:

View file

@ -198,6 +198,9 @@
/* Define to 1 if you have the <callback.h> 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

View file

@ -1773,10 +1773,14 @@ GSPrivateCheckTasks()
/*
* 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))
{

11
configure vendored
View file

@ -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; }

View file

@ -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