diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 288eec5545..50125b558c 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1531,6 +1531,7 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void); +SWITCH_DECLARE(void) switch_core_setrlimits(void); ///\} diff --git a/src/switch.c b/src/switch.c index b6b8de8361..90ffd45cfe 100644 --- a/src/switch.c +++ b/src/switch.c @@ -430,6 +430,8 @@ int main(int argc, char *argv[]) set_high_priority(); } + switch_core_setrlimits(); + #ifndef WIN32 if (runas_user || runas_group) { if(change_user_group(runas_user, runas_group) < 0) { diff --git a/src/switch_core.c b/src/switch_core.c index 49af5ad161..99352360c9 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -661,6 +661,44 @@ static void load_mime_types(void) } + +SWITCH_DECLARE(void) switch_core_setrlimits(void) +{ +#ifdef HAVE_SETRLIMIT + struct rlimit rlp; + + /* + Setting the stack size on FreeBSD results in an instant crash. + + If anyone knows how to fix this, + feel free to submit a patch to http://jira.freeswitch.org + */ + +#ifndef __FreeBSD__ + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = SWITCH_THREAD_STACKSIZE; + rlp.rlim_max = SWITCH_THREAD_STACKSIZE; + setrlimit(RLIMIT_STACK, &rlp); +#endif + + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = 999999; + rlp.rlim_max = 999999; + setrlimit(RLIMIT_NOFILE, &rlp); + + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = RLIM_INFINITY; + rlp.rlim_max = RLIM_INFINITY; + + setrlimit(RLIMIT_CPU, &rlp); + setrlimit(RLIMIT_DATA, &rlp); + setrlimit(RLIMIT_FSIZE, &rlp); + setrlimit(RLIMIT_AS, &rlp); +#endif + return; +} + + SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switch_bool_t console, const char **err) { switch_xml_t xml = NULL, cfg = NULL; @@ -702,41 +740,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc switch_core_set_variable("base_dir", SWITCH_GLOBAL_dirs.base_dir); -#ifdef HAVE_SETRLIMIT - { - struct rlimit rlp; - - /* - Setting the stack size on FreeBSD results in an instant crash. - - If anyone knows how to fix this, - feel free to submit a patch to http://jira.freeswitch.org - */ - -#ifndef __FreeBSD__ - memset(&rlp, 0, sizeof(rlp)); - rlp.rlim_cur = SWITCH_THREAD_STACKSIZE; - rlp.rlim_max = SWITCH_THREAD_STACKSIZE; - setrlimit(RLIMIT_STACK, &rlp); -#endif - - memset(&rlp, 0, sizeof(rlp)); - rlp.rlim_cur = 999999; - rlp.rlim_max = 999999; - setrlimit(RLIMIT_NOFILE, &rlp); - - memset(&rlp, 0, sizeof(rlp)); - rlp.rlim_cur = RLIM_INFINITY; - rlp.rlim_max = RLIM_INFINITY; - - setrlimit(RLIMIT_CPU, &rlp); - setrlimit(RLIMIT_DATA, &rlp); - setrlimit(RLIMIT_FSIZE, &rlp); - setrlimit(RLIMIT_AS, &rlp); - } - -#endif - if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) { apr_terminate();