[asterisk-commits] trunk r30603 - in /trunk: asterisk.c cli.c include/asterisk/logger.h logger.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 26 12:48:18 MST 2006


Author: file
Date: Fri May 26 14:48:17 2006
New Revision: 30603

URL: http://svn.digium.com/view/asterisk?rev=30603&view=rev
Log:
Add ability to disable log / verbose output to remote consoles (issue #6524 reported by mavetju)

Modified:
    trunk/asterisk.c
    trunk/cli.c
    trunk/include/asterisk/logger.h
    trunk/logger.c

Modified: trunk/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/asterisk.c?rev=30603&r1=30602&r2=30603&view=diff
==============================================================================
--- trunk/asterisk.c (original)
+++ trunk/asterisk.c Fri May 26 14:48:17 2006
@@ -160,6 +160,7 @@
 
 int option_verbose = 0;				/*!< Verbosity level */
 int option_debug = 0;				/*!< Debug level */
+int option_mute = 0;				/*!< Mute console */
 
 double option_maxload = 0.0;			/*!< Max load avg on system */
 int option_maxcalls = 0;			/*!< Max number of active calls */
@@ -176,6 +177,7 @@
 	int fd;				/*!< File descriptor */
 	int p[2];			/*!< Pipe */
 	pthread_t t;			/*!< Thread of handler */
+	int mute;			/*!< Is the console muted for logs */
 };
 
 struct ast_atexit {
@@ -681,6 +683,51 @@
 }
 
 /*!
+ * mute or unmute a console from logging
+ */
+void ast_console_mute(int fd) {
+	int x;
+	for (x=0;x<AST_MAX_CONNECTS; x++) {
+		if (fd == consoles[x].fd) {
+			if (consoles[x].mute) {
+				consoles[x].mute=0;
+				ast_cli(fd, "Console is not muted anymore.\n");
+			} else {
+				consoles[x].mute=1;
+				ast_cli(fd, "Console is muted.\n");
+			}
+			return;
+		}
+	}
+	ast_cli(fd, "Couldn't find remote console.\n");
+}
+
+/*!
+ * log the string to all attached console clients
+ */
+static void ast_network_puts_mutable(const char *string)
+{
+	int x;
+	for (x=0;x < AST_MAX_CONNECTS; x++) {
+		if (consoles[x].mute)
+			continue;;
+		if (consoles[x].fd > -1) 
+			fdprint(consoles[x].p[1], string);
+	}
+}
+
+/*!
+ * log the string to the console, and all attached
+ * console clients
+ */
+void ast_console_puts_mutable(const char *string)
+{
+	fputs(string, stdout);
+	fflush(stdout);
+	ast_network_puts_mutable(string);
+}
+
+/*!
  * write the string to all attached console clients
  */
 static void ast_network_puts(const char *string)
@@ -711,14 +758,14 @@
 		if ((t = alloca(strlen(s) + 2))) {
 			sprintf(t, "\r%s", s);
 			if (complete)
-				ast_network_puts(t);
+				ast_network_puts_mutable(t);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory\n");
-			ast_network_puts(s);
+			ast_network_puts_mutable(s);
 		}
 	} else {
 		if (complete)
-			ast_network_puts(s);
+			ast_network_puts_mutable(s);
 	}
 }
 
@@ -819,6 +866,7 @@
 					flags = fcntl(consoles[x].p[1], F_GETFL);
 					fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
 					consoles[x].fd = s;
+					consoles[x].mute = 0;
 					if (ast_pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
 						ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
 						close(consoles[x].p[0]);
@@ -2025,6 +2073,10 @@
 	fdprint(ast_consock, tmp);
 	snprintf(tmp, sizeof(tmp), "set debug atleast %d", option_debug);
 	fdprint(ast_consock, tmp);
+	if (option_mute) {
+		snprintf(tmp, sizeof(tmp), "logger mute");
+		fdprint(ast_consock, tmp);
+	}
 	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
 	remotehostname = hostname;
 	if (getenv("HOME")) 
@@ -2093,6 +2145,7 @@
 	printf("   -I              Enable internal timing if Zaptel timer is available\n");
 	printf("   -L <load>       Limit the maximum load average before rejecting new calls\n");
 	printf("   -M <value>      Limit the maximum number of calls to the specified value\n");
+	printf("   -m              Mute the console from debugging and verbose output\n");
 	printf("   -n              Disable console colorization\n");
 	printf("   -p              Run as pseudo-realtime thread\n");
 	printf("   -q              Quiet mode (suppress output)\n");
@@ -2311,7 +2364,7 @@
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
 	/* Check for options */
-	while ((c = getopt(argc, argv, "tThfdvVqprRgciInx:U:G:C:L:M:")) != -1) {
+	while ((c = getopt(argc, argv, "mtThfdvVqprRgciInx:U:G:C:L:M:")) != -1) {
 		switch (c) {
 		case 'F':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
@@ -2340,6 +2393,10 @@
 			break;
 		case 'v':
 			option_verbose++;
+			ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
+			break;
+		case 'm':
+			option_mute++;
 			ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
 			break;
 		case 'M':

Modified: trunk/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/cli.c?rev=30603&r1=30602&r2=30603&view=diff
==============================================================================
--- trunk/cli.c (original)
+++ trunk/cli.c Fri May 26 14:48:17 2006
@@ -114,6 +114,11 @@
 "       no messages should be displayed. Equivalent to -d[d[d...]]\n"
 "       on startup.\n";
 
+static char logger_mute_help[] = 
+"Usage: logger mute\n"
+"       Disables logging output to the current console, making it possible to\n"
+"       gather information without being disturbed by scrolling lines.\n";
+
 static char softhangup_help[] =
 "Usage: soft hangup <channel>\n"
 "       Request that a channel be hung up. The hangup takes effect\n"
@@ -210,6 +215,14 @@
 		ast_cli(fd, "Core debug is at least %d\n", option_debug);
 	else if (oldval > 0 && option_debug == 0)
 		ast_cli(fd, "Core debug is now OFF\n");
+	return RESULT_SUCCESS;
+}
+
+static int handle_logger_mute(int fd, int argc, char *argv[])
+{
+	if (argc != 2)
+		return RESULT_SHOWUSAGE;
+	ast_console_mute(fd);
 	return RESULT_SUCCESS;
 }
 
@@ -919,6 +932,7 @@
 	{ { "reload", NULL }, handle_reload, "Reload configuration", reload_help, complete_mod_2 },
 	{ { "set", "debug", NULL }, handle_set_debug, "Set level of debug chattiness", set_debug_help },
 	{ { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help },
+	{ { "logger", "mute", NULL }, handle_logger_mute, "Disable logging output to a console", logger_mute_help },
 	{ { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch_3 },
 	{ { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help, complete_show_channels },
 	{ { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },

Modified: trunk/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/logger.h?rev=30603&r1=30602&r2=30603&view=diff
==============================================================================
--- trunk/include/asterisk/logger.h (original)
+++ trunk/include/asterisk/logger.h Fri May 26 14:48:17 2006
@@ -82,6 +82,9 @@
 int ast_verbose_dmesg(void (*verboser)(const char *string, int opos, int replacelast, int complete));
 void ast_console_puts(const char *string);
 
+extern void ast_console_puts_mutable(const char *string);
+extern void ast_console_mute(int fd);
+
 #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__
 
 #ifdef LOG_DEBUG

Modified: trunk/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/logger.c?rev=30603&r1=30602&r2=30603&view=diff
==============================================================================
--- trunk/logger.c (original)
+++ trunk/logger.c Fri May 26 14:48:17 2006
@@ -756,11 +756,11 @@
 						term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
 						term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
 					
-					ast_console_puts(buf);
+					ast_console_puts_mutable(buf);
 					va_start(ap, fmt);
 					vsnprintf(buf, sizeof(buf), fmt, ap);
 					va_end(ap);
-					ast_console_puts(buf);
+					ast_console_puts_mutable(buf);
 				}
 			/* File channels */
 			} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {



More information about the asterisk-commits mailing list