diff options
author | Russell Bryant <russell@russellbryant.com> | 2007-10-15 19:19:01 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2007-10-15 19:19:01 +0000 |
commit | ac9a6dce2588468f47ca41c9f1a1b6eff18e6081 (patch) | |
tree | 5df4bfa6cafe6de79952c04d8b06a9b0fd2ac798 /main | |
parent | 1acdae4f1234b305a352de81166e74b9cbc84f3d (diff) |
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().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@85648 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/utils.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/main/utils.c b/main/utils.c index 80fadfdcc..320516e33 100644 --- a/main/utils.c +++ b/main/utils.c @@ -716,6 +716,10 @@ static const char *locktype2str(enum ast_lock_type type) 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 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_ return NULL; } - ast_cli(a->fd, "\n" + ast_str_append(&str, 0, "\n" "=======================================================================\n" "=== Currently Held Locks ==============================================\n" "=======================================================================\n" @@ -741,12 +745,13 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_ 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,14 +760,18 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_ 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; } |