From 997e6dd0d5f6f99b50dc88f06319e027530589f8 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Sat, 1 Oct 2005 15:41:27 +0000 Subject: add ast_build_string_va(), which accepts a varargs list directly ensure the _entire_ manager_event() output is either queued or sent via ast_carefulwrite() git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6708 f38db490-d61c-443f-a65b-d21fe96a405b --- manager.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'manager.c') diff --git a/manager.c b/manager.c index 059c7298d..5e8cac8be 100755 --- a/manager.c +++ b/manager.c @@ -1473,13 +1473,16 @@ static int append_event(struct mansession *s, const char *str) int manager_event(int category, char *event, char *fmt, ...) { struct mansession *s; + char auth[80]; char tmp[4096]; - char auth[256]; + char *tmp_next = tmp; + size_t tmp_left = sizeof(tmp) - 2; va_list ap; - authority_to_str(category, auth, sizeof(auth)); + 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); - vsnprintf(tmp, sizeof(tmp) - 3, fmt, ap); + ast_build_string_va(&tmp_next, &tmp_left, fmt, ap); va_end(ap); strcat(tmp, "\r\n"); @@ -1492,11 +1495,9 @@ int manager_event(int category, char *event, char *fmt, ...) continue; ast_mutex_lock(&s->__lock); - ast_cli(s->fd, "Event: %s\r\n", event); - ast_cli(s->fd, "Privilege: %s\r\n", auth); if (s->busy) { append_event(s, tmp); - } else if (ast_carefulwrite(s->fd, tmp, strlen(tmp), 100) < 0) { + } else if (ast_carefulwrite(s->fd, tmp, sizeof(tmp) - tmp_left + 1, 100) < 0) { ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n"); s->dead = 1; pthread_kill(s->t, SIGURG); -- cgit v1.2.3