[asterisk-commits] russell: branch 1.4 r85647 - /branches/1.4/main/utils.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Oct 15 14:11:38 CDT 2007
Author: russell
Date: Mon Oct 15 14:11:38 2007
New Revision: 85647
URL: http://svn.digium.com/view/asterisk?view=rev&rev=85647
Log:
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:
branches/1.4/main/utils.c
Modified: branches/1.4/main/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/utils.c?view=diff&rev=85647&r1=85646&r2=85647
==============================================================================
--- branches/1.4/main/utils.c (original)
+++ branches/1.4/main/utils.c Mon Oct 15 14:11:38 2007
@@ -707,8 +707,12 @@
static int handle_show_locks(int fd, int argc, char *argv[])
{
struct thr_lock_info *lock_info;
-
- ast_cli(fd, "\n"
+ struct ast_dynamic_str *str;
+
+ if (!(str = ast_dynamic_str_create(4096)))
+ return RESULT_FAILURE;
+
+ ast_dynamic_str_append(&str, 0, "\n"
"=======================================================================\n"
"=== Currently Held Locks ==============================================\n"
"=======================================================================\n"
@@ -719,12 +723,13 @@
pthread_mutex_lock(&lock_infos_lock.mutex);
AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
int i;
- ast_cli(fd, "=== Thread ID: %u (%s)\n", (int) lock_info->thread_id,
+ ast_dynamic_str_append(&str, 0, "=== Thread ID: %u (%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(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_dynamic_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,
@@ -733,15 +738,19 @@
lock_info->locks[i].times_locked);
}
pthread_mutex_unlock(&lock_info->lock);
- ast_cli(fd, "=== -------------------------------------------------------------------\n"
+ ast_dynamic_str_append(&str, 0, "=== -------------------------------------------------------------------\n"
"===\n");
}
pthread_mutex_unlock(&lock_infos_lock.mutex);
- ast_cli(fd, "=======================================================================\n"
+ ast_dynamic_str_append(&str, 0, "=======================================================================\n"
"\n");
- return 0;
+ ast_cli(fd, "%s", str->str);
+
+ free(str);
+
+ return RESULT_SUCCESS;
}
static char show_locks_help[] =
More information about the asterisk-commits
mailing list