mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 19:38:22 +00:00
don't take session lock in astman_send_error() and astman_send_response(), since it is no longer needed
don't build authority string and event string for every session in manager_event(), do it only once git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6704 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
43
manager.c
43
manager.c
@@ -331,21 +331,29 @@ struct ast_variable *astman_get_variables(struct message *m)
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE:
|
||||||
|
Callers of astman_send_error(), astman_send_response() or astman_send_ack() must EITHER
|
||||||
|
hold the session lock _or_ be running in an action callback (in which case s->busy will
|
||||||
|
be non-zero). In either of these cases, there is no need to lock-protect the session's
|
||||||
|
fd, since no other output will be sent (events will be queued), and no input will
|
||||||
|
be read until either the current action finishes or get_input() obtains the session
|
||||||
|
lock.
|
||||||
|
*/
|
||||||
|
|
||||||
void astman_send_error(struct mansession *s, struct message *m, char *error)
|
void astman_send_error(struct mansession *s, struct message *m, char *error)
|
||||||
{
|
{
|
||||||
char *id = astman_get_header(m,"ActionID");
|
char *id = astman_get_header(m,"ActionID");
|
||||||
ast_mutex_lock(&s->__lock);
|
|
||||||
ast_cli(s->fd, "Response: Error\r\n");
|
ast_cli(s->fd, "Response: Error\r\n");
|
||||||
if (id && !ast_strlen_zero(id))
|
if (id && !ast_strlen_zero(id))
|
||||||
ast_cli(s->fd, "ActionID: %s\r\n",id);
|
ast_cli(s->fd, "ActionID: %s\r\n",id);
|
||||||
ast_cli(s->fd, "Message: %s\r\n\r\n", error);
|
ast_cli(s->fd, "Message: %s\r\n\r\n", error);
|
||||||
ast_mutex_unlock(&s->__lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
|
void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
|
||||||
{
|
{
|
||||||
char *id = astman_get_header(m,"ActionID");
|
char *id = astman_get_header(m,"ActionID");
|
||||||
ast_mutex_lock(&s->__lock);
|
|
||||||
ast_cli(s->fd, "Response: %s\r\n", resp);
|
ast_cli(s->fd, "Response: %s\r\n", resp);
|
||||||
if (id && !ast_strlen_zero(id))
|
if (id && !ast_strlen_zero(id))
|
||||||
ast_cli(s->fd, "ActionID: %s\r\n",id);
|
ast_cli(s->fd, "ActionID: %s\r\n",id);
|
||||||
@@ -353,7 +361,6 @@ void astman_send_response(struct mansession *s, struct message *m, char *resp, c
|
|||||||
ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
|
ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
|
||||||
else
|
else
|
||||||
ast_cli(s->fd, "\r\n");
|
ast_cli(s->fd, "\r\n");
|
||||||
ast_mutex_unlock(&s->__lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void astman_send_ack(struct mansession *s, struct message *m, char *msg)
|
void astman_send_ack(struct mansession *s, struct message *m, char *msg)
|
||||||
@@ -1467,31 +1474,37 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
{
|
{
|
||||||
struct mansession *s;
|
struct mansession *s;
|
||||||
char tmp[4096];
|
char tmp[4096];
|
||||||
|
char auth[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
ast_mutex_lock(&sessionlock);
|
authority_to_str(category, auth, sizeof(auth));
|
||||||
s = sessions;
|
|
||||||
while(s) {
|
|
||||||
if (((s->readperm & category) == category) && ((s->send_events & category) == category)) {
|
|
||||||
ast_mutex_lock(&s->__lock);
|
|
||||||
ast_cli(s->fd, "Event: %s\r\n", event);
|
|
||||||
ast_cli(s->fd, "Privilege: %s\r\n", authority_to_str(category, tmp, sizeof(tmp)));
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(tmp, sizeof(tmp) - 3, fmt, ap);
|
vsnprintf(tmp, sizeof(tmp) - 3, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
strcat(tmp, "\r\n");
|
strcat(tmp, "\r\n");
|
||||||
|
|
||||||
|
ast_mutex_lock(&sessionlock);
|
||||||
|
for (s = sessions; s; s = s->next) {
|
||||||
|
if ((s->readperm & category) != category)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((s->send_events & category) != category)
|
||||||
|
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) {
|
if (s->busy) {
|
||||||
append_event(s, tmp);
|
append_event(s, tmp);
|
||||||
} else if (ast_carefulwrite(s->fd,tmp,strlen(tmp),100) < 0) {
|
} else if (ast_carefulwrite(s->fd, tmp, strlen(tmp), 100) < 0) {
|
||||||
ast_log(LOG_WARNING, "Disconnecting slow 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);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&s->__lock);
|
ast_mutex_unlock(&s->__lock);
|
||||||
}
|
}
|
||||||
s = s->next;
|
|
||||||
}
|
|
||||||
ast_mutex_unlock(&sessionlock);
|
ast_mutex_unlock(&sessionlock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user