mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@6708 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
13
manager.c
13
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);
|
||||
|
Reference in New Issue
Block a user