From d1672353449f4e151ec73ace31ca9789c99f4f6b Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Mon, 3 Oct 2005 19:40:03 +0000 Subject: [PATCH] don't build manager event output until it is needed git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6709 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- manager.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/manager.c b/manager.c index 5e8cac8be0..1df35bdae7 100755 --- a/manager.c +++ b/manager.c @@ -1474,18 +1474,11 @@ int manager_event(int category, char *event, char *fmt, ...) { struct mansession *s; char auth[80]; - char tmp[4096]; + char tmp[4096] = ""; char *tmp_next = tmp; size_t tmp_left = sizeof(tmp) - 2; va_list ap; - ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n", - event, authority_to_str(category, auth, sizeof(auth))); - va_start(ap, fmt); - ast_build_string_va(&tmp_next, &tmp_left, fmt, ap); - va_end(ap); - strcat(tmp, "\r\n"); - ast_mutex_lock(&sessionlock); for (s = sessions; s; s = s->next) { if ((s->readperm & category) != category) @@ -1494,10 +1487,21 @@ int manager_event(int category, char *event, char *fmt, ...) if ((s->send_events & category) != category) continue; + if (ast_strlen_zero(tmp)) { + ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n", + event, authority_to_str(category, auth, sizeof(auth))); + va_start(ap, fmt); + ast_build_string_va(&tmp_next, &tmp_left, fmt, ap); + va_end(ap); + *tmp_next++ = '\r'; + *tmp_next++ = '\n'; + *tmp_next = '\0'; + } + ast_mutex_lock(&s->__lock); if (s->busy) { append_event(s, tmp); - } else if (ast_carefulwrite(s->fd, tmp, sizeof(tmp) - tmp_left + 1, 100) < 0) { + } else if (ast_carefulwrite(s->fd, tmp, tmp_next - tmp, 100) < 0) { ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n"); s->dead = 1; pthread_kill(s->t, SIGURG);