mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
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
This commit is contained in:
21
main/utils.c
21
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user