[svn-commits] file: trunk r47933 - /trunk/main/asterisk.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Nov 22 10:41:08 MST 2006


Author: file
Date: Wed Nov 22 11:41:07 2006
New Revision: 47933

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47933
Log:
Add support to set the maximum number of files open when Asterisk loads using the 'maxfiles' configuration option. (issue #7499 reported by rkarlsba)

Modified:
    trunk/main/asterisk.c

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=47933&r1=47932&r2=47933
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Nov 22 11:41:07 2006
@@ -1011,6 +1011,29 @@
 	if (n == 0 && option_debug)	
 		printf("Huh?  Child handler, but nobody there?\n");
 	signal(sig, child_handler);
+}
+
+/*! \brief Set maximum open files */
+static void set_ulimit(int value)
+{
+	struct rlimit l = {0, 0};
+	
+	if (value <= 0) {
+		ast_log(LOG_WARNING, "Unable to change max files open to invalid value %i\n",value);
+		return;
+	}
+	
+	l.rlim_cur = value;
+	l.rlim_max = value;
+	
+	if (setrlimit(RLIMIT_NOFILE, &l)) {
+		ast_log(LOG_WARNING, "Unable to disable core size resource limit: %s\n",strerror(errno));
+		return;
+	}
+	
+	ast_log(LOG_NOTICE, "Setting max files open to %d\n",value);
+	
+	return;
 }
 
 /*! \brief Set an X-term or screen title */
@@ -2293,6 +2316,9 @@
 			} else if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
 				option_maxload = 0.0;
 			}
+		/* Set the maximum amount of open files */
+		} else if (!strcasecmp(v->name, "maxfiles")) {
+			set_ulimit(atoi(v->value));
 		/* What user to run as */
 		} else if (!strcasecmp(v->name, "runuser")) {
 			ast_copy_string(ast_config_AST_RUN_USER, v->value, sizeof(ast_config_AST_RUN_USER));



More information about the svn-commits mailing list