From 38b7f7b4a474cfb9cd79acd09515a84d0e6d746b Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Wed, 18 May 2005 01:49:13 +0000 Subject: [PATCH] Add optional call limit git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5712 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- asterisk.8.gz | Bin 2458 -> 2547 bytes asterisk.c | 12 +++++++++++- asterisk.sgml | 11 +++++++++++ cli.c | 7 ++++++- include/asterisk/options.h | 1 + include/asterisk/pbx.h | 3 +++ pbx.c | 33 ++++++++++++++++++++++++++++++++- 7 files changed, 64 insertions(+), 3 deletions(-) diff --git a/asterisk.8.gz b/asterisk.8.gz index abbd0c45312bcbb54d0220a7c64661cf50b7f7b3..d05b828286821f76e2b02f98eac700d760fae784 100755 GIT binary patch delta 2534 zcmV)ABzYG`Ynn=00UujbY*gBb89X*0Nq$!ZyUQ2ecxX}_@UP+Bsqyu zvB_RLX>jh`NKdrAV=Ot;EJQCKEDzV8M??2=#}vGhe8(oaow?+NeottFwQp zvQjRb;k!QTHvD$>DQ-9~mGnw@MY_yhteadoRa+PQNa(6|cB{w&{DOk^tCk@x6h2sm z3h4xviDgiKTO}?FWpeS+(~qC?T#upRSCxi|b@``BGFjb-lj(AGy_hZkdLmB#f`9M+ zENa>3p?bY*QaiJkbQXO`7az>XxRqvTXWIl4o{`u^UX?{+`n4qm!%a<>g{F zU(N3CPLj!detd8sNQzAZ&ux?pjROdeT_<*hPK$)%t~2Gu-03aQDlVKfX(80Nw2%hq zKAm5Ge0wtzGXw213L24rusT&@p?qx$f^s^0SiBh}(};d-bqV~7EA4~R>n3Px#Od_% z3QD4&rQK(9ar$6q^EV=g%uepL$pN!VYc|R$lk!hVSQT}tLSda0b|Y*kAUvE!)^&+| zqfIDjuzKyR%o4}8Ltt2%sV#Q*LYuT~GUx|?y3=JeZ0+K_pBLlvx920VxLA(F7i()Dqzf2#L;~?g!pkpcIc;81Hdoev zsR<)t+TqG6nSrFN599|5Q&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6x7&^S%bImL#8$@@?0<&({W)&kzbBO0)W0Tp z-9CTDESblL#8V|(tLq_U6KNRl^rIg33QqL>ipf*)gDb~aez@0D|3)Phq3K_4T0FW_ z9q6SWQS4r7kqW(B{X~yKYw%MWt;yHb&HWK38`REN&diI1d+WPdqW^@*2V*#>uX xW?Oy%W3name, "transcode_via_sln")) { option_transcode_slin = ast_true(v->value); + } else if (!strcasecmp(v->name, "maxcalls")) { + if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || + (option_maxcalls < 0)) { + option_maxcalls = 0; + } } v = v->next; } @@ -1711,7 +1717,7 @@ int main(int argc, char *argv[]) } */ /* Check for options */ - while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:")) != -1) { + while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:M:")) != -1) { switch(c) { case 'd': option_debug++; @@ -1743,6 +1749,10 @@ int main(int argc, char *argv[]) option_verbose++; option_nofork++; break; + case 'M': + if ((sscanf(optarg, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) + option_maxcalls = 0; + break; case 'q': option_quiet++; break; diff --git a/asterisk.sgml b/asterisk.sgml index b84ad0020a..abee2e6787 100755 --- a/asterisk.sgml +++ b/asterisk.sgml @@ -26,6 +26,7 @@ user group command +value @@ -141,6 +142,16 @@ + + -M value + + + Limits the maximum number of calls to the specified value. This can + be useful to prevent a system from being brought down by terminating + too many simultaneous calls. + + + -n diff --git a/cli.c b/cli.c index 141ac09ae7..80150eefed 100755 --- a/cli.c +++ b/cli.c @@ -429,8 +429,13 @@ static int handle_chanlist(int fd, int argc, char *argv[]) ast_mutex_unlock(&c->lock); c = ast_channel_walk_locked(c); } - if(!concise) + if(!concise) { ast_cli(fd, "%d active channel(s)\n", numchans); + if (option_maxcalls) + ast_cli(fd, "%d of %d max active call(s) (%5.2f%% of capacity)\n", ast_active_calls(), option_maxcalls, ((float)ast_active_calls() / (float)option_maxcalls) * 100.0); + else + ast_cli(fd, "%d active call(s)\n", ast_active_calls()); + } return RESULT_SUCCESS; } diff --git a/include/asterisk/options.h b/include/asterisk/options.h index 598ea31db0..9d962bbe5a 100755 --- a/include/asterisk/options.h +++ b/include/asterisk/options.h @@ -33,6 +33,7 @@ extern int option_exec_includes; extern int option_cache_record_files; extern int option_timestamp; extern int option_transcode_slin; +extern int option_maxcalls; extern char defaultlanguage[]; extern time_t ast_startuptime; extern time_t ast_lastreloadtime; diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 19331acff3..b0f92b60a5 100755 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -602,6 +602,9 @@ int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exte struct ast_custom_function* ast_custom_function_find(char *name); int ast_custom_function_unregister(struct ast_custom_function *acf); int ast_custom_function_register(struct ast_custom_function *acf); + +/* Number of active calls */ +int ast_active_calls(void); /*! executes a read operation on a function */ /*! diff --git a/pbx.c b/pbx.c index ebadafd361..803c3fca47 100755 --- a/pbx.c +++ b/pbx.c @@ -213,6 +213,9 @@ static struct varshead globals; static int autofallthrough = 0; +AST_MUTEX_DEFINE_STATIC(maxcalllock); +static int countcalls = 0; + AST_MUTEX_DEFINE_STATIC(acflock); /* Lock for the custom function list */ static struct ast_custom_function *acf_root = NULL; @@ -2232,7 +2235,7 @@ int ast_exec_extension(struct ast_channel *c, const char *context, const char *e return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_EXEC); } -int ast_pbx_run(struct ast_channel *c) +static int __ast_pbx_run(struct ast_channel *c) { int firstpass = 1; char digit; @@ -2497,6 +2500,34 @@ int ast_pbx_start(struct ast_channel *c) return 0; } +int ast_pbx_run(struct ast_channel *c) +{ + int res = 0; + ast_mutex_lock(&maxcalllock); + if (option_maxcalls) { + if (countcalls >= option_maxcalls) { + ast_log(LOG_NOTICE, "Maximum call limit of %d calls exceeded by '%s'!\n", option_maxcalls, c->name); + res = -1; + } + } + if (!res) + countcalls++; + ast_mutex_unlock(&maxcalllock); + if (!res) { + res = __ast_pbx_run(c); + ast_mutex_lock(&maxcalllock); + if (countcalls > 0) + countcalls--; + ast_mutex_unlock(&maxcalllock); + } + return res; +} + +int ast_active_calls(void) +{ + return countcalls; +} + int pbx_set_autofallthrough(int newval) { int oldval;