mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 06:48:25 +00:00
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
This commit is contained in:
22
manager.c
22
manager.c
@@ -1474,18 +1474,11 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
{
|
{
|
||||||
struct mansession *s;
|
struct mansession *s;
|
||||||
char auth[80];
|
char auth[80];
|
||||||
char tmp[4096];
|
char tmp[4096] = "";
|
||||||
char *tmp_next = tmp;
|
char *tmp_next = tmp;
|
||||||
size_t tmp_left = sizeof(tmp) - 2;
|
size_t tmp_left = sizeof(tmp) - 2;
|
||||||
va_list ap;
|
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);
|
ast_mutex_lock(&sessionlock);
|
||||||
for (s = sessions; s; s = s->next) {
|
for (s = sessions; s; s = s->next) {
|
||||||
if ((s->readperm & category) != category)
|
if ((s->readperm & category) != category)
|
||||||
@@ -1494,10 +1487,21 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
if ((s->send_events & category) != category)
|
if ((s->send_events & category) != category)
|
||||||
continue;
|
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);
|
ast_mutex_lock(&s->__lock);
|
||||||
if (s->busy) {
|
if (s->busy) {
|
||||||
append_event(s, tmp);
|
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");
|
ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n");
|
||||||
s->dead = 1;
|
s->dead = 1;
|
||||||
pthread_kill(s->t, SIGURG);
|
pthread_kill(s->t, SIGURG);
|
||||||
|
|||||||
Reference in New Issue
Block a user