Skip to content

Commit

Permalink
Use closefrom() if available
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 14, 2023
1 parent 15ff083 commit ae9892d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2023-11-14 Richard Frith-Macdonald <[email protected]>

* 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 <[email protected]>

* Source/NSISO8601DateFormatter.m:
Expand Down
3 changes: 3 additions & 0 deletions Headers/GNUstepBase/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Source/NSTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
11 changes: 11 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae9892d

Please sign in to comment.