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] = "";
/* 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;
}
}
*/
/* 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++;
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;
<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>
</para>
</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>
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;
}
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;
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 */
/*!
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;
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;
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;