[asterisk-commits] russell: trunk r85648 - in /trunk: ./ main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 15 14:19:02 CDT 2007


Author: russell
Date: Mon Oct 15 14:19:01 2007
New Revision: 85648

URL: http://svn.digium.com/view/asterisk?view=rev&rev=85648
Log:
Merged revisions 85647 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r85647 | russell | 2007-10-15 14:11:38 -0500 (Mon, 15 Oct 2007) | 5 lines

The loop in the handler for the "core show locks" could potentially block for
some amount of time.  Be a little bit more careful and prepare all of the
output in an intermediary buffer while holding a global resource.  Then, after
releasing it, send the output to ast_cli().

........

Modified:
    trunk/   (props changed)
    trunk/main/utils.c

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

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=85648&r1=85647&r2=85648
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Mon Oct 15 14:19:01 2007
@@ -716,6 +716,10 @@
 static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct thr_lock_info *lock_info;
+	struct ast_str *str;
+
+	if (!(str = ast_str_create(4096)))
+		return CLI_FAILURE;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -730,7 +734,7 @@
 		return NULL;
 	}
 
-	ast_cli(a->fd, "\n" 
+	ast_str_append(&str, 0, "\n" 
 	               "=======================================================================\n"
 	               "=== Currently Held Locks ==============================================\n"
 	               "=======================================================================\n"
@@ -741,12 +745,13 @@
 	pthread_mutex_lock(&lock_infos_lock.mutex);
 	AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
 		int i;
-		ast_cli(a->fd, "=== Thread ID: %d (%s)\n", (int) lock_info->thread_id,
+		ast_str_append(&str, 0, "=== Thread ID: %d (%s)\n", (int) lock_info->thread_id,
 			lock_info->thread_name);
 		pthread_mutex_lock(&lock_info->lock);
 		for (i = 0; i < lock_info->num_locks; i++) {
-			ast_cli(a->fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n", 
-				lock_info->locks[i].pending > 0 ? "Waiting for " : lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
+			ast_str_append(&str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n", 
+				lock_info->locks[i].pending > 0 ? "Waiting for " : 
+					lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
 				lock_info->locks[i].file, 
 				locktype2str(lock_info->locks[i].type),
 				lock_info->locks[i].line_num,
@@ -755,13 +760,17 @@
 				lock_info->locks[i].times_locked);
 		}
 		pthread_mutex_unlock(&lock_info->lock);
-		ast_cli(a->fd, "=== -------------------------------------------------------------------\n"
+		ast_str_append(&str, 0, "=== -------------------------------------------------------------------\n"
 		               "===\n");
 	}
 	pthread_mutex_unlock(&lock_infos_lock.mutex);
 
-	ast_cli(a->fd, "=======================================================================\n"
+	ast_str_append(&str, 0, "=======================================================================\n"
 	               "\n");
+
+	ast_cli(a->fd, "%s", str->str);
+
+	free(str);
 
 	return 0;
 }




More information about the asterisk-commits mailing list