aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-12 23:06:12 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-12 23:06:12 +0000
commitc0765c5fbf583f6cd61d72e1f8cd4c985059888f (patch)
tree653bff8fd1cd0a6a58455c6156638d07bac2ad95
parent67837440f9c41169fd3ca5ac47f6729004b03003 (diff)
Some platforms (notably, the BSDs) have a more efficient implementation called
closefrom(3). git-svn-id: http://svn.digium.com/svn/asterisk/trunk@168522 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xconfigure5
-rw-r--r--configure.ac2
-rw-r--r--include/asterisk/autoconfig.h.in3
-rw-r--r--main/app.c13
4 files changed, 18 insertions, 5 deletions
diff --git a/configure b/configure
index 06d46fada..1b6d730f3 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.ac Revision: 164802 .
+# From configure.ac Revision: 166058 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for asterisk 1.6.
#
@@ -15678,7 +15678,8 @@ done
-for ac_func in asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid sysctl swapctl
+
+for ac_func in asprintf atexit closefrom dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid sysctl swapctl
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
diff --git a/configure.ac b/configure.ac
index 58a8b8e1e..bca65c7a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,7 +337,7 @@ AC_FUNC_STRNLEN
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
AC_CHECK_FUNCS([glob])
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 35c5fce7c..6cb55487a 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -153,6 +153,9 @@
/* Define to 1 if your system has a working `chown' function. */
#undef HAVE_CHOWN
+/* Define to 1 if you have the `closefrom' function. */
+#undef HAVE_CLOSEFROM
+
/* Define this to indicate the ${COS_DESCRIP} library */
#undef HAVE_COS
diff --git a/main/app.c b/main/app.c
index d3d3b3784..bda021d56 100644
--- a/main/app.c
+++ b/main/app.c
@@ -33,6 +33,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <regex.h>
#include <sys/file.h> /* added this to allow to compile, sorry! */
#include <signal.h>
+#include <sys/time.h> /* for getrlimit(2) */
+#include <sys/resource.h> /* for getrlimit(2) */
+#include <stdlib.h> /* for closefrom(3) */
#include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
#include "asterisk/channel.h"
@@ -1839,18 +1842,24 @@ int ast_get_encoded_str(const char *stream, char *result, size_t result_size)
void ast_close_fds_above_n(int n)
{
+#ifdef HAVE_CLOSEFROM
+ closefrom(n + 1);
+#else
int x, null;
+ struct rlimit rl;
+ getrlimit(RLIMIT_NOFILE, &rl);
null = open("/dev/null", O_RDONLY);
- for (x = n + 1; x <= (null >= 8192 ? null : 8192); x++) {
+ for (x = n + 1; x < rl.rlim_max; x++) {
if (x != null) {
/* Side effect of dup2 is that it closes any existing fd without error.
* This prevents valgrind and other debugging tools from sending up
* false error reports. */
- dup2(null, x);
+ while (dup2(null, x) < 0 && errno == EINTR);
close(x);
}
}
close(null);
+#endif
}
int ast_safe_fork(int stop_reaper)