[svn-commits] rmudgett: trunk r291076 - in /trunk: ./ main/cli.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Oct 11 11:46:11 CDT 2010


Author: rmudgett
Date: Mon Oct 11 11:44:32 2010
New Revision: 291076

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291076
Log:
Merged revisions 291075 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r291075 | rmudgett | 2010-10-11 11:42:54 -0500 (Mon, 11 Oct 2010) | 22 lines
  
  Merged revisions 291073 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ........
    r291073 | rmudgett | 2010-10-11 11:39:17 -0500 (Mon, 11 Oct 2010) | 15 lines
    
    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:
    trunk/   (props changed)
    trunk/main/cli.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: trunk/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cli.c?view=diff&rev=291076&r1=291075&r2=291076
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Mon Oct 11 11:44:32 2010
@@ -386,6 +386,7 @@
 {
 	int oldval;
 	int newlevel;
+	unsigned int is_debug;
 	int atleast = 0;
 	int fd = a->fd;
 	int argc = a->argc;
@@ -454,22 +455,23 @@
 		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;
 
-		mll = debug ? &debug_modules : &verbose_modules;
+		mll = is_debug ? &debug_modules : &verbose_modules;
 
 		AST_RWLIST_WRLOCK(mll);
 		while ((ml = AST_RWLIST_REMOVE_HEAD(mll, entry))) {
 			ast_free(ml);
 		}
-		ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+		ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
 		AST_RWLIST_UNLOCK(mll);
 
 		goto done;
@@ -481,21 +483,27 @@
 	if (sscanf(argv[e->args + atleast], "%30d", &newlevel) != 1)
 		return CLI_SHOWUSAGE;
 	if (argc == e->args + atleast + 2) {
-		unsigned int debug = (*what == 'C');
+		/* We have specified a module name. */
 		char *mod = ast_strdupa(argv[e->args + atleast + 1]);
-
-		mll = debug ? &debug_modules : &verbose_modules;
 
 		if ((strlen(mod) > 3) && !strcasecmp(mod + strlen(mod) - 3, ".so")) {
 			mod[strlen(mod) - 3] = '\0';
 		}
 
+		mll = is_debug ? &debug_modules : &verbose_modules;
+
 		AST_RWLIST_WRLOCK(mll);
 
-		if ((ml = find_module_level(mod, debug)) && !newlevel) {
+		ml = find_module_level(mod, is_debug);
+		if (!newlevel) {
+			if (!ml) {
+				/* Specified off for a nonexistent entry. */
+				AST_RWLIST_UNLOCK(mll);
+				return CLI_SUCCESS;
+			}
 			AST_RWLIST_REMOVE(mll, ml, entry);
 			if (AST_RWLIST_EMPTY(mll))
-				ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+				ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
 			AST_RWLIST_UNLOCK(mll);
 			ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, ml->level, mod);
 			ast_free(ml);
@@ -508,23 +516,37 @@
 				AST_RWLIST_UNLOCK(mll);
 				return CLI_SUCCESS;
 			}
-		} else if (!(ml = ast_calloc(1, sizeof(*ml) + strlen(mod) + 1))) {
-			AST_RWLIST_UNLOCK(mll);
-			return CLI_FAILURE;
-		}
-
-		oldval = ml->level;
-		ml->level = newlevel;
-		strcpy(ml->module, mod);
-
-		ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
-
-		AST_RWLIST_INSERT_TAIL(mll, ml, entry);
+			oldval = ml->level;
+			ml->level = newlevel;
+		} else {
+			ml = ast_calloc(1, sizeof(*ml) + strlen(mod) + 1);
+			if (!ml) {
+				AST_RWLIST_UNLOCK(mll);
+				return CLI_FAILURE;
+			}
+			oldval = ml->level;
+			ml->level = newlevel;
+			strcpy(ml->module, mod);
+			AST_RWLIST_INSERT_TAIL(mll, ml, entry);
+		}
+
+		ast_set_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+
 		AST_RWLIST_UNLOCK(mll);
 
 		ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, ml->level, ml->module);
 
 		return CLI_SUCCESS;
+	} else if (!newlevel) {
+		/* Specified level as 0 instead of off. */
+		mll = is_debug ? &debug_modules : &verbose_modules;
+
+		AST_RWLIST_WRLOCK(mll);
+		while ((ml = AST_RWLIST_REMOVE_HEAD(mll, entry))) {
+			ast_free(ml);
+		}
+		ast_clear_flag(&ast_options, is_debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+		AST_RWLIST_UNLOCK(mll);
 	}
 
 done:




More information about the svn-commits mailing list