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
1.2-netsec
Kevin P. Fleming 20 years ago
parent 9835bc4330
commit d167235344

@ -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);

Loading…
Cancel
Save