summaryrefslogtreecommitdiff
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2006-11-22 17:41:07 +0000
committerJoshua Colp <jcolp@digium.com>2006-11-22 17:41:07 +0000
commit7b4a5105b2c89f1a262a0337c062100cf68e239f (patch)
tree24275753f7b971e087eff7636053d006f24f84e4 /main/asterisk.c
parentdb08a0f3463322cde32bae16ba457cc9c222588d (diff)
Add support to set the maximum number of files open when Asterisk loads using the 'maxfiles' configuration option. (issue #7499 reported by rkarlsba)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47933 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 7e32df78a..b29bbd4c9 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -1013,6 +1013,29 @@ static void child_handler(int sig)
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 */
static void set_title(char *text)
{
@@ -2293,6 +2316,9 @@ static void ast_readconfig(void)
} 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));