[asterisk-commits] rmudgett: branch 1.6.2 r291073 - /branches/1.6.2/main/cli.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Oct 11 11:39:19 CDT 2010
Author: rmudgett
Date: Mon Oct 11 11:39:17 2010
New Revision: 291073
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291073
Log:
Fixed infinite loop in verbose/debug message output.
Setting the module/filename specific message level and then changing it
resulted in the linked list being looped on itself. Traversing this
linked list is an infinite loop if what you are looking for is not in the
list.
Also plugged some CLI parsing holes in the associated CLI command:
* Removing a nonexistent module from the list actually added it with a
level of zero.
* Setting the non-module specific level to zero is now equivalent to
setting it to "off" as documented.
Modified:
branches/1.6.2/main/cli.c
Modified: branches/1.6.2/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/main/cli.c?view=diff&rev=291073&r1=291072&r2=291073
==============================================================================
--- branches/1.6.2/main/cli.c (original)
+++ branches/1.6.2/main/cli.c Mon Oct 11 11:39:17 2010
@@ -363,6 +363,7 @@
{
int oldval;
int newlevel;
+ unsigned int is_debug;
int atleast = 0;
int fd = a->fd;
int argc = a->argc;
@@ -432,21 +433,22 @@
dst = &option_debug;
oldval = option_debug;
what = "Core debug";
+ is_debug = 1;
} else {
dst = &option_verbose;
oldval = option_verbose;
what = "Verbosity";
+ is_debug = 0;
}
if (argc == e->args + 1 && !strcasecmp(argv[e->args], "off")) {
- unsigned int debug = (*what == 'C');
newlevel = 0;
- dfl = debug ? &debug_files : &verbose_files;
+ dfl = is_debug ? &debug_files : &verbose_files;
AST_RWLIST_WRLOCK(dfl);
while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry)))
ast_free(adf);
- ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+ ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
AST_RWLIST_UNLOCK(dfl);
goto done;
@@ -458,17 +460,23 @@
if (sscanf(argv[e->args + atleast], "%30d", &newlevel) != 1)
return CLI_SHOWUSAGE;
if (argc == e->args + atleast + 2) {
- unsigned int debug = (*what == 'C');
- dfl = debug ? &debug_files : &verbose_files;
-
+ /* We have specified a module name. */
fn = argv[e->args + atleast + 1];
+ dfl = is_debug ? &debug_files : &verbose_files;
+
AST_RWLIST_WRLOCK(dfl);
- if ((adf = find_debug_file(fn, debug)) && !newlevel) {
+ adf = find_debug_file(fn, is_debug);
+ if (!newlevel) {
+ if (!adf) {
+ /* Specified off for a nonexistent entry. */
+ AST_RWLIST_UNLOCK(dfl);
+ return CLI_SUCCESS;
+ }
AST_RWLIST_REMOVE(dfl, adf, entry);
if (AST_RWLIST_EMPTY(dfl))
- ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+ ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
AST_RWLIST_UNLOCK(dfl);
ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, adf->level, fn);
ast_free(adf);
@@ -481,23 +489,36 @@
AST_RWLIST_UNLOCK(dfl);
return CLI_SUCCESS;
}
- } else if (!(adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1))) {
- AST_RWLIST_UNLOCK(dfl);
- return CLI_FAILURE;
- }
-
- oldval = adf->level;
- adf->level = newlevel;
- strcpy(adf->filename, fn);
-
- ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
-
- AST_RWLIST_INSERT_TAIL(dfl, adf, entry);
+ oldval = adf->level;
+ adf->level = newlevel;
+ } else {
+ adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1);
+ if (!adf) {
+ AST_RWLIST_UNLOCK(dfl);
+ return CLI_FAILURE;
+ }
+ oldval = adf->level;
+ adf->level = newlevel;
+ strcpy(adf->filename, fn);
+ AST_RWLIST_INSERT_TAIL(dfl, adf, entry);
+ }
+
+ ast_set_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+
AST_RWLIST_UNLOCK(dfl);
ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, adf->level, adf->filename);
return CLI_SUCCESS;
+ } else if (!newlevel) {
+ /* Specified level as 0 instead of off. */
+ dfl = is_debug ? &debug_files : &verbose_files;
+
+ AST_RWLIST_WRLOCK(dfl);
+ while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry)))
+ ast_free(adf);
+ ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+ AST_RWLIST_UNLOCK(dfl);
}
done:
More information about the asterisk-commits
mailing list