[asterisk-commits] tilghman: trunk r168522 - in /trunk: ./ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 12 17:06:12 CST 2009


Author: tilghman
Date: Mon Jan 12 17:06:12 2009
New Revision: 168522

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=168522
Log:
Some platforms (notably, the BSDs) have a more efficient implementation called
closefrom(3).

Modified:
    trunk/configure
    trunk/configure.ac
    trunk/include/asterisk/autoconfig.h.in
    trunk/main/app.c

Modified: trunk/configure.ac
URL: http://svn.digium.com/svn-view/asterisk/trunk/configure.ac?view=diff&rev=168522&r1=168521&r2=168522
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Jan 12 17:06:12 2009
@@ -337,7 +337,7 @@
 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])
 

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=168522&r1=168521&r2=168522
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Mon Jan 12 17:06:12 2009
@@ -152,6 +152,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

Modified: trunk/main/app.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/app.c?view=diff&rev=168522&r1=168521&r2=168522
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Mon Jan 12 17:06:12 2009
@@ -33,6 +33,9 @@
 #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 @@
 
 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)




More information about the asterisk-commits mailing list