From 0f833ca28df788878494fb33882195a7825736e2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 18 Dec 2007 16:55:39 +0000 Subject: [PATCH] add self-adjusting rlimit stuff for systems that support it git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6864 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch.c | 14 ++++++++++++++ src/switch_core.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/switch.c b/src/switch.c index d4715aa9a4..a8f07af0c1 100644 --- a/src/switch.c +++ b/src/switch.c @@ -235,6 +235,9 @@ int main(int argc, char *argv[]) "\t-g [group] -- specify group to switch to\n" #endif "\t-help -- this message\n" +#ifdef HAVE_SETRLIMIT + "\t-core -- dump cores\n" +#endif "\t-hp -- enable high priority settings\n" "\t-nosql -- disable internal sql scoreboard\n" "\t-stop -- stop freeswitch\n" @@ -307,6 +310,17 @@ int main(int argc, char *argv[]) known_opt++; } #endif +#ifdef HAVE_SETRLIMIT + if (argv[x] && !strcmp(argv[x], "-core")) { + struct rlimit rlp; + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = RLIM_INFINITY; + rlp.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CORE, &rlp); + known_opt++; + } +#endif + if (argv[x] && !strcmp(argv[x], "-hp")) { high_prio++; known_opt++; diff --git a/src/switch_core.c b/src/switch_core.c index d0d6bd4d4d..27425c72e4 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -36,6 +36,7 @@ #include #include #include "private/switch_core_pvt.h" +#include SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs = { 0 }; @@ -683,6 +684,33 @@ 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; + + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = SWITCH_THREAD_STACKSIZE; + rlp.rlim_max = SWITCH_THREAD_STACKSIZE; + setrlimit(RLIMIT_STACK, &rlp); + + 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(); return SWITCH_STATUS_MEMERR; @@ -712,6 +740,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc switch_core_session_ctl(SCSC_LOGLEVEL, &level); } +#ifdef HAVE_SETRLIMIT + } else if (!strcasecmp(var, "dump-cores")) { + struct rlimit rlp; + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = RLIM_INFINITY; + rlp.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CORE, &rlp); +#endif + } else if (!strcasecmp(var, "mailer-app")) { runtime.mailer_app = switch_core_strdup(runtime.memory_pool, val); } else if (!strcasecmp(var, "mailer-app-args")) {