[asterisk-commits] rmudgett: branch rmudgett/ast_verb r405087 - in /team/rmudgett/ast_verb: ./ c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 7 20:30:27 CST 2014


Author: rmudgett
Date: Tue Jan  7 20:30:16 2014
New Revision: 405087

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405087
Log:
Implemented the server console verbosity level API and made use it.

Modified:
    team/rmudgett/ast_verb/UPGRADE.txt
    team/rmudgett/ast_verb/configs/logger.conf.sample
    team/rmudgett/ast_verb/include/asterisk/logger.h
    team/rmudgett/ast_verb/main/asterisk.c
    team/rmudgett/ast_verb/main/cli.c
    team/rmudgett/ast_verb/main/logger.c

Modified: team/rmudgett/ast_verb/UPGRADE.txt
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/UPGRADE.txt?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/UPGRADE.txt (original)
+++ team/rmudgett/ast_verb/UPGRADE.txt Tue Jan  7 20:30:16 2014
@@ -19,6 +19,12 @@
 === UPGRADE-10.txt -- Upgrade info for 1.8 to 10
 ===
 ===========================================================
+
+From 11.7 to 11.8:
+Configuration Files:
+ - The 'verbose' setting in logger.conf still takes an optional argument,
+   specifying the verbosity level for each logging destination.  However,
+   the default is to once again follow the current root console level.
 
 From 11.6 to 11.7:
 ConfBridge

Modified: team/rmudgett/ast_verb/configs/logger.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/configs/logger.conf.sample?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/configs/logger.conf.sample (original)
+++ team/rmudgett/ast_verb/configs/logger.conf.sample Tue Jan  7 20:30:16 2014
@@ -83,24 +83,25 @@
 ;    fax
 ;    security
 ;
-; Special filename "console" represents the system console
+; Special filename "console" represents the root console
 ;
 ; Filenames can either be relative to the standard Asterisk log directory
 ; (see 'astlogdir' in asterisk.conf), or absolute paths that begin with
 ; '/'.
 ;
+; Verbose takes an optional argument, in the form of an integer level.
+; Verbose messages with higher levels will not be logged to the file.  If
+; the verbose level is not specified, it will log verbose messages following
+; the current level of the root console.
+;
 ; Special level name "*" means all levels, even dynamic levels registered
 ; by modules after the logger has been initialized (this means that loading
 ; and unloading modules that create/remove dynamic logger levels will result
 ; in these levels being included on filenames that have a level name of "*",
-; without any need to perform a 'logger reload' or similar operation). Note
-; that there is no value in specifying both "*" and specific level names for
-; a filename; the "*" level means all levels, and the remaining level names
-; will be ignored.
-;
-; Verbose takes an additional argument, in the form of an integer level.
-; Messages with higher levels will be ignored.  If verbose is specified at
-; all, it will default to 3.
+; without any need to perform a 'logger reload' or similar operation).
+; Note that there is no value in specifying both "*" and specific level names
+; for a filename; the "*" level means all levels.  The only exception is if
+; you need to specify a specific verbose level. e.g, "verbose(3),*".
 ;
 ; We highly recommend that you DO NOT turn on debug mode if you are simply
 ; running a production system.  Debug mode turns on a LOT of extra messages,

Modified: team/rmudgett/ast_verb/include/asterisk/logger.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/include/asterisk/logger.h?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/include/asterisk/logger.h (original)
+++ team/rmudgett/ast_verb/include/asterisk/logger.h Tue Jan  7 20:30:16 2014
@@ -368,8 +368,62 @@
 		ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
 } while (0)
 
-#define ast_verb(level, ...) __ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, __VA_ARGS__)
-#define ast_verb_callid(level, callid, ...) __ast_verbose_callid(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, callid, __VA_ARGS__)
+extern int ast_verb_sys_level;
+
+#define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level)
+
+#define ast_verb(level, ...) \
+	do { \
+		if (VERBOSITY_ATLEAST(level) ) { \
+			__ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, __VA_ARGS__); \
+		} \
+	} while (0)
+
+#define ast_verb_callid(level, callid, ...) \
+	do { \
+		if (VERBOSITY_ATLEAST(level) ) { \
+			__ast_verbose_callid(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, callid, __VA_ARGS__); \
+		} \
+	} while (0)
+
+/*!
+ * \brief Re-evaluate the system max verbosity level (ast_verb_sys_level).
+ *
+ * \return Nothing
+ */
+void ast_verb_update(void);
+
+/*!
+ * \brief Register this thread's console verbosity level pointer.
+ *
+ * \param level Where the verbose level value is.
+ *
+ * \return Nothing
+ */
+void ast_verb_console_register(int *level);
+
+/*!
+ * \brief Unregister this thread's console verbosity level.
+ *
+ * \return Nothing
+ */
+void ast_verb_console_unregister(void);
+
+/*!
+ * \brief Get this thread's console verbosity level.
+ *
+ * \retval verbosity level of the console.
+ */
+int ast_verb_console_get(void);
+
+/*!
+ * \brief Set this thread's console verbosity level.
+ *
+ * \param verb_level New level to set.
+ *
+ * \return Nothing
+ */
+void ast_verb_console_set(int verb_level);
 
 #ifndef _LOGGER_BACKTRACE_H
 #define _LOGGER_BACKTRACE_H

Modified: team/rmudgett/ast_verb/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/main/asterisk.c?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/main/asterisk.c (original)
+++ team/rmudgett/ast_verb/main/asterisk.c Tue Jan  7 20:30:16 2014
@@ -191,6 +191,9 @@
 struct ast_flags ast_options = { AST_DEFAULT_OPTIONS };
 struct ast_flags ast_compat = { 0 };
 
+/*! Maximum active system verbosity level. */
+int ast_verb_sys_level;
+
 int option_verbose;				/*!< Verbosity level */
 int option_debug;				/*!< Debug level */
 double option_maxload;				/*!< Max load avg on system */
@@ -219,6 +222,8 @@
 	int uid;			/*!< Remote user ID. */
 	int gid;			/*!< Remote group ID. */
 	int levels[NUMLOGLEVELS];	/*!< Which log levels are enabled for the console */
+	/*! Verbosity level of this console. */
+	int option_verbose;
 };
 
 struct ast_atexit {
@@ -480,7 +485,8 @@
 		ast_cli(a->fd, "  Maximum open file handles:   %d\n", option_maxfiles);
 	else
 		ast_cli(a->fd, "  Maximum open file handles:   Not set\n");
-	ast_cli(a->fd, "  Verbosity:                   %d\n", option_verbose);
+	ast_cli(a->fd, "  Root console verbosity:      %d\n", option_verbose);
+	ast_cli(a->fd, "  Current console verbosity:   %d\n", ast_verb_console_get());
 	ast_cli(a->fd, "  Debug level:                 %d\n", option_debug);
 	ast_cli(a->fd, "  Maximum load average:        %lf\n", option_maxload);
 #if defined(HAVE_SYSINFO)
@@ -1233,6 +1239,7 @@
 
 static void network_verboser(const char *s)
 {
+/* BUGBUG change this to put to each network connection if the verbose level is allowed. */
 	ast_network_puts_mutable(s, __LOG_VERBOSE);
 }
 
@@ -1297,6 +1304,7 @@
 	return result;
 }
 
+/* This is the thread running the remote console on the main process. */
 static void *netconsole(void *vconsole)
 {
 	struct console *con = vconsole;
@@ -1312,6 +1320,7 @@
 		ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
 	snprintf(outbuf, sizeof(outbuf), "%s/%ld/%s\n", hostname, (long)ast_mainpid, ast_get_version());
 	fdprint(con->fd, outbuf);
+	ast_verb_console_register(&con->option_verbose);
 	for (;;) {
 		fds[0].fd = con->fd;
 		fds[0].events = POLLIN;
@@ -1320,17 +1329,6 @@
 		fds[1].events = POLLIN;
 		fds[1].revents = 0;
 
-/*
- * BUGBUG this is the thread running the remote console on the main process.
- *
- * Need to have this thread keep track of its option_verbose value.
- *
- * Need to have this thread register/unregister its option_verbose value
- * to update the global max verbose setting.
- *
- * Need to have ast_cli_command_multiple_full() processing of "core set verbose"
- * updated to deal with different threads.
- */
 		res = ast_poll(fds, 2, -1);
 		if (res < 0) {
 			if (errno != EINTR)
@@ -1385,6 +1383,7 @@
 				break;
 		}
 	}
+	ast_verb_console_unregister();
 	if (!ast_opt_hide_connect) {
 		ast_verb(3, "Remote UNIX connection disconnected\n");
 	}
@@ -1437,24 +1436,25 @@
 					}
 					if (socketpair(AF_LOCAL, SOCK_STREAM, 0, consoles[x].p)) {
 						ast_log(LOG_ERROR, "Unable to create pipe: %s\n", strerror(errno));
-						consoles[x].fd = -1;
 						fdprint(s, "Server failed to create pipe\n");
 						close(s);
 						break;
 					}
 					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 = 1; /* Default is muted, we will un-mute if necessary */
 					/* Default uid and gid to -2, so then in cli.c/cli_has_permissions() we will be able
 					   to know if the user didn't send the credentials. */
 					consoles[x].uid = -2;
 					consoles[x].gid = -2;
+					/* Server default of remote console verbosity level is OFF. */
+					consoles[x].option_verbose = 0;
+					consoles[x].fd = s;
 					if (ast_pthread_create_detached_background(&consoles[x].t, NULL, netconsole, &consoles[x])) {
+						consoles[x].fd = -1;
 						ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
 						close(consoles[x].p[0]);
 						close(consoles[x].p[1]);
-						consoles[x].fd = -1;
 						fdprint(s, "Server failed to spawn thread\n");
 						close(s);
 					}
@@ -2047,12 +2047,12 @@
 	return 1;
 }
 
+/* This is the main console CLI command handler.  Run by the main() thread. */
 static void consolehandler(char *s)
 {
 	printf("%s", term_end());
 	fflush(stdout);
 
-/* BUGBUG this is the main console CLI command handler.  Run by the main() thread. */
 	/* Called when readline data is available */
 	if (!ast_all_zeros(s))
 		ast_el_add_history(s);
@@ -2121,15 +2121,15 @@
 
 			if (strncasecmp(shrunk + 17, "atleast ", 8) == 0) {
 				if (sscanf(shrunk + 25, "%30d", &verbose_new) == 1) {
-					if (verbose_new > option_verbose) {
-						option_verbose = verbose_new;
+					if (ast_verb_console_get() < verbose_new) {
+						ast_verb_console_set(verbose_new);
 					}
 				}
 			} else if (strncasecmp(shrunk + 17, "off", 3) == 0) {
-				option_verbose = 0;
+				ast_verb_console_set(0);
 			} else {
 				if (sscanf(shrunk + 17, "%30d", &verbose_new) == 1) {
-					option_verbose = verbose_new;
+					ast_verb_console_set(verbose_new);
 				}
 			}
 		}
@@ -3548,6 +3548,7 @@
 		kill(canary_pid, SIGKILL);
 }
 
+/* Execute CLI commands on startup.  Run by main() thread. */
 static void run_startup_commands(void)
 {
 	int fd;
@@ -3567,7 +3568,6 @@
 		return;
 	}
 
-/* BUGBUG this is to execute CLI commands on startup.  Run by main() thread. */
 	for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next) {
 		if (ast_true(v->value))
 			ast_cli_command(fd, v->name);
@@ -3977,6 +3977,9 @@
 		}
 	}
 
+	/* Initial value of the maximum active system verbosity level. */
+	ast_verb_sys_level = option_verbose;
+
 	if (ast_tryconnect()) {
 		/* One is already running */
 		if (ast_opt_remote) {

Modified: team/rmudgett/ast_verb/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/main/cli.c?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/main/cli.c (original)
+++ team/rmudgett/ast_verb/main/cli.c Tue Jan  7 20:30:16 2014
@@ -576,7 +576,6 @@
 	int newlevel;
 	int atleast = 0;
 	const char *argv3 = a->argv ? S_OR(a->argv[3], "") : "";
-	int *dst;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -638,16 +637,15 @@
 	}
 
 	/* Update verbose level */
-/* BUGBUG need to change current console verbose level. */
-	dst = &option_verbose;
-	oldval = option_verbose;
-	if (!atleast || newlevel > *dst) {
-		*dst = newlevel;
-/* BUGBUG reevaluate max active verbose level. */
+	oldval = ast_verb_console_get();
+	if (!atleast || newlevel > oldval) {
+		ast_verb_console_set(newlevel);
+	} else {
+		newlevel = oldval;
 	}
 
 	/* Report verbose level status */
-	status_debug_verbose(a, "Console verbose", oldval, *dst);
+	status_debug_verbose(a, "Console verbose", oldval, newlevel);
 
 	return CLI_SUCCESS;
 }

Modified: team/rmudgett/ast_verb/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/main/logger.c?view=diff&rev=405087&r1=405086&r2=405087
==============================================================================
--- team/rmudgett/ast_verb/main/logger.c (original)
+++ team/rmudgett/ast_verb/main/logger.c Tue Jan  7 20:30:16 2014
@@ -118,7 +118,7 @@
 	int disabled;
 	/*! syslog facility */
 	int facility;
-	/*! Verbosity level */
+	/*! Verbosity level. (-1 if use option_verbose for the level.) */
 	int verbosity;
 	/*! Type of log channel */
 	enum logtypes type;
@@ -243,24 +243,32 @@
 	unsigned int res = 0;
 	char *stringp = ast_strdupa(s);
 	unsigned int x;
-
-	*verbosity = 3;
+	int verb_level;
+
+	/* Default to using option_verbose as the verbosity level of the logging channel.  */
+	verb_level = -1;
 
 	while ((w = strsep(&stringp, ","))) {
-		w = ast_skip_blanks(w);
-
+		w = ast_strip(w);
+		if (ast_strlen_zero(w)) {
+			continue;
+		}
 		if (!strcmp(w, "*")) {
 			res = 0xFFFFFFFF;
-			break;
-		} else if (!strncasecmp(w, "verbose(", 8) && sscanf(w + 8, "%d)", verbosity) == 1) {
-			res |= (1 << __LOG_VERBOSE);
-		} else for (x = 0; x < ARRAY_LEN(levels); x++) {
-			if (levels[x] && !strcasecmp(w, levels[x])) {
-				res |= (1 << x);
-				break;
+		} else if (!strncasecmp(w, "verbose(", 8)) {
+			if (levels[__LOG_VERBOSE] && sscanf(w + 8, "%30u)", &verb_level) == 1) {
+				res |= (1 << __LOG_VERBOSE);
 			}
-		}
-	}
+		} else {
+			for (x = 0; x < ARRAY_LEN(levels); x++) {
+				if (levels[x] && !strcasecmp(w, levels[x])) {
+					res |= (1 << x);
+					break;
+				}
+			}
+		}
+	}
+	*verbosity = verb_level;
 
 	return res;
 }
@@ -333,7 +341,14 @@
 		chan->type = LOGTYPE_FILE;
 	}
 	chan->logmask = make_components(chan->components, lineno, &chan->verbosity);
-
+	if (chan->type == LOGTYPE_CONSOLE) {
+		/*
+		 * Force to use the root console verbose level so if the
+		 * user specified any verbose level then it does not interfere
+		 * with calculating the ast_verb_sys_level value.
+		 */
+		chan->verbosity = -1;
+	}
 	return chan;
 }
 
@@ -829,10 +844,12 @@
 	if (logfiles.queue_log) {
 		res = logger_queue_restart(queue_rotate);
 		AST_RWLIST_UNLOCK(&logchannels);
+		ast_verb_update();
 		ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
 		ast_verb(1, "Asterisk Queue Logger restarted\n");
 	} else {
 		AST_RWLIST_UNLOCK(&logchannels);
+		ast_verb_update();
 	}
 
 	return res;
@@ -1033,7 +1050,9 @@
 
 	if (logmsg->level == __LOG_VERBOSE) {
 		char *tmpmsg = ast_strdupa(logmsg->message + 1);
+
 		level = VERBOSE_MAGIC2LEVEL(logmsg->message);
+
 		/* Iterate through the list of verbosers and pass them the log message string */
 		AST_RWLIST_RDLOCK(&verbosers);
 		AST_RWLIST_TRAVERSE(&verbosers, v, list)
@@ -1059,7 +1078,8 @@
 			if (chan->disabled) {
 				continue;
 			}
-			if (logmsg->level == __LOG_VERBOSE && level > chan->verbosity) {
+			if (logmsg->level == __LOG_VERBOSE
+				&& (((chan->verbosity < 0) ? option_verbose : chan->verbosity)) < level) {
 				continue;
 			}
 
@@ -1236,6 +1256,7 @@
 
 	/* create log channels */
 	init_logger_chain(0 /* locked */, NULL);
+	ast_verb_update();
 	logger_initialized = 1;
 
 	return 0;
@@ -1374,7 +1395,7 @@
 	return 0;
 }
 
-int ast_callid_threadassoc_remove()
+int ast_callid_threadassoc_remove(void)
 {
 	struct ast_callid **pointing;
 	pointing = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
@@ -1884,6 +1905,148 @@
 	}
 }
 
+/*! Console verbosity level node. */
+struct verb_console {
+	/*! List node link */
+	AST_LIST_ENTRY(verb_console) node;
+	/*! Console verbosity level. */
+	int *level;
+};
+
+/*! Registered console verbosity levels */
+static AST_RWLIST_HEAD_STATIC(verb_consoles, verb_console);
+
+/*! ast_verb_update() reentrancy protection lock. */
+AST_MUTEX_DEFINE_STATIC(verb_update_lock);
+
+void ast_verb_update(void)
+{
+	struct logchannel *log;
+	struct verb_console *console;
+	int verb_level;
+
+	ast_mutex_lock(&verb_update_lock);
+
+	AST_RWLIST_RDLOCK(&verb_consoles);
+
+	/* Default to the root console verbosity. */
+	verb_level = option_verbose;
+
+	/* Determine max remote console level. */
+	AST_LIST_TRAVERSE(&verb_consoles, console, node) {
+		if (verb_level < *console->level) {
+			verb_level = *console->level;
+		}
+	}
+	AST_RWLIST_UNLOCK(&verb_consoles);
+
+	/* Determine max logger channel level. */
+	AST_RWLIST_RDLOCK(&logchannels);
+	AST_RWLIST_TRAVERSE(&logchannels, log, list) {
+		if (verb_level < log->verbosity) {
+			verb_level = log->verbosity;
+		}
+	}
+	AST_RWLIST_UNLOCK(&logchannels);
+
+	ast_verb_sys_level = verb_level;
+
+	ast_mutex_unlock(&verb_update_lock);
+}
+
+/*!
+ * \internal
+ * \brief Unregister a console verbose level.
+ *
+ * \param console Which console to unregister.
+ *
+ * \return Nothing
+ */
+static void verb_console_unregister(struct verb_console *console)
+{
+	AST_RWLIST_WRLOCK(&verb_consoles);
+	console = AST_RWLIST_REMOVE(&verb_consoles, console, node);
+	AST_RWLIST_UNLOCK(&verb_consoles);
+	if (console) {
+		ast_verb_update();
+	}
+}
+
+static void verb_console_free(void *v_console)
+{
+	struct verb_console *console = v_console;
+
+	verb_console_unregister(console);
+	ast_free(console);
+}
+
+/*! Thread specific console verbosity level node. */
+AST_THREADSTORAGE_CUSTOM(my_verb_console, NULL, verb_console_free);
+
+void ast_verb_console_register(int *level)
+{
+	struct verb_console *console;
+
+	console = ast_threadstorage_get(&my_verb_console, sizeof(struct verb_console));
+	if (!console || !level) {
+		return;
+	}
+	console->level = level;
+
+	AST_RWLIST_WRLOCK(&verb_consoles);
+	AST_RWLIST_INSERT_HEAD(&verb_consoles, console, node);
+	AST_RWLIST_UNLOCK(&verb_consoles);
+	ast_verb_update();
+}
+
+void ast_verb_console_unregister(void)
+{
+	struct verb_console *console;
+
+	console = ast_threadstorage_get(&my_verb_console, sizeof(struct verb_console));
+	if (!console) {
+		return;
+	}
+	verb_console_unregister(console);
+}
+
+int ast_verb_console_get(void)
+{
+	struct verb_console *console;
+	int verb_level;
+
+	console = ast_threadstorage_get(&my_verb_console, sizeof(struct verb_console));
+	AST_RWLIST_RDLOCK(&verb_consoles);
+	if (!console) {
+		verb_level = 0;
+	} else if (console->level) {
+		verb_level = *console->level;
+	} else {
+		verb_level = option_verbose;
+	}
+	AST_RWLIST_UNLOCK(&verb_consoles);
+	return verb_level;
+}
+
+void ast_verb_console_set(int verb_level)
+{
+	struct verb_console *console;
+
+	console = ast_threadstorage_get(&my_verb_console, sizeof(struct verb_console));
+	if (!console) {
+		return;
+	}
+
+	AST_RWLIST_WRLOCK(&verb_consoles);
+	if (console->level) {
+		*console->level = verb_level;
+	} else {
+		option_verbose = verb_level;
+	}
+	AST_RWLIST_UNLOCK(&verb_consoles);
+	ast_verb_update();
+}
+
 int ast_register_verbose(void (*v)(const char *string))
 {
 	struct verb *verb;




More information about the asterisk-commits mailing list