diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-18 01:49:13 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-18 01:49:13 +0000 |
commit | e2c8bb9c440289d09415aa7464bdfa921b91f426 (patch) | |
tree | d354c66fada464fed80154e7002ee445c4d36d52 | |
parent | 6c8c36cb1296babe111fc188cf94358137df932d (diff) |
Add optional call limit
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5712 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-x | asterisk.8.gz | bin | 2458 -> 2547 bytes | |||
-rwxr-xr-x | asterisk.c | 12 | ||||
-rwxr-xr-x | asterisk.sgml | 11 | ||||
-rwxr-xr-x | cli.c | 7 | ||||
-rwxr-xr-x | include/asterisk/options.h | 1 | ||||
-rwxr-xr-x | include/asterisk/pbx.h | 3 | ||||
-rwxr-xr-x | pbx.c | 33 |
7 files changed, 64 insertions, 3 deletions
diff --git a/asterisk.8.gz b/asterisk.8.gz Binary files differindex abbd0c453..d05b82828 100755 --- a/asterisk.8.gz +++ b/asterisk.8.gz diff --git a/asterisk.c b/asterisk.c index f42193fe3..308519ba2 100755 --- a/asterisk.c +++ b/asterisk.c @@ -87,6 +87,7 @@ int option_timestamp = 0; int option_overrideconfig = 0; int option_reconnect = 0; int option_transcode_slin = 1; +int option_maxcalls = 0; int fully_booted = 0; char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR; char debug_filename[AST_FILENAME_MAX] = ""; @@ -1658,6 +1659,11 @@ static void ast_readconfig(void) { /* Build transcode paths via SLINEAR, instead of directly */ } else if (!strcasecmp(v->name, "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 b84ad0020..abee2e678 100755 --- a/asterisk.sgml +++ b/asterisk.sgml @@ -26,6 +26,7 @@ <arg><option>-U </option><replaceable class="parameter">user</replaceable></arg> <arg><option>-G </option><replaceable class="parameter">group</replaceable></arg> <arg><option>-x </option><replaceable class="parameter">command</replaceable></arg> +<arg><option>-M </option><replaceable class="parameter">value</replaceable></arg> </cmdsynopsis> <cmdsynopsis> @@ -142,6 +143,16 @@ </listitem> </varlistentry> <varlistentry> + <term>-M <replaceable class="parameter">value</replaceable></term> + <listitem> + <para> + 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. + </para> + </listitem> + </varlistentry> + <varlistentry> <term>-n</term> <listitem> <para> @@ -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 598ea31db..9d962bbe5 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 19331acff..b0f92b60a 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 */ /*! @@ -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; |