[Asterisk-cvs] asterisk asterisk.8.gz, 1.2, 1.3 asterisk.c, 1.153, 1.154 asterisk.sgml, 1.2, 1.3 cli.c, 1.80, 1.81 pbx.c, 1.244, 1.245

markster at lists.digium.com markster at lists.digium.com
Tue May 17 21:44:03 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv2481

Modified Files:
	asterisk.8.gz asterisk.c asterisk.sgml cli.c pbx.c 
Log Message:
Add optional call limit


Index: asterisk.8.gz
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.8.gz,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
Binary files /tmp/cvsYyE7ly and /tmp/cvsvCiICW differ

Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- asterisk.c	15 May 2005 03:21:51 -0000	1.153
+++ asterisk.c	18 May 2005 01:49:12 -0000	1.154
@@ -87,6 +87,7 @@
 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 @@
 		/* 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 @@
 	}
 	*/
 	/* 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 @@
 			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;

Index: asterisk.sgml
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.sgml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- asterisk.sgml	11 Mar 2005 07:24:10 -0000	1.2
+++ asterisk.sgml	18 May 2005 01:49:12 -0000	1.3
@@ -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>

Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- cli.c	15 May 2005 03:03:48 -0000	1.80
+++ cli.c	18 May 2005 01:49:12 -0000	1.81
@@ -429,8 +429,13 @@
 		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;
 }
 

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.244
retrieving revision 1.245
diff -u -d -r1.244 -r1.245
--- pbx.c	15 May 2005 23:32:38 -0000	1.244
+++ pbx.c	18 May 2005 01:49:12 -0000	1.245
@@ -213,6 +213,9 @@
 
 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 @@
 	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 @@
 	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;




More information about the svn-commits mailing list