aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-15 19:11:38 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-15 19:11:38 +0000
commitf30db15b46dc04e50fbde47e34e615a2079388e7 (patch)
tree748169d47d6aa52a01b1a34b9dd93222b9d9108f
parentc579505ba6b9287bfcb4a0fea785c6cf12423f37 (diff)
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: http://svn.digium.com/svn/asterisk/branches/1.4@85647 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/utils.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/main/utils.c b/main/utils.c
index 5d4bd1cdc..8c2c568f1 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -707,8 +707,12 @@ static const char *locktype2str(enum ast_lock_type type)
static int handle_show_locks(int fd, int argc, char *argv[])
{
struct thr_lock_info *lock_info;
+ struct ast_dynamic_str *str;
- ast_cli(fd, "\n"
+ 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 @@ static int handle_show_locks(int fd, int argc, char *argv[])
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 @@ static int handle_show_locks(int fd, int argc, char *argv[])
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[] =