mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Fix manager bug (can't destroy a session while a thread is using it!)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6698 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -82,6 +82,8 @@ struct mansession {
|
|||||||
int fd;
|
int fd;
|
||||||
/*! Whether or not we're busy doing an action */
|
/*! Whether or not we're busy doing an action */
|
||||||
int busy;
|
int busy;
|
||||||
|
/*! Whether or not we're "dead" */
|
||||||
|
int dead;
|
||||||
/*! Logged in username */
|
/*! Logged in username */
|
||||||
char username[80];
|
char username[80];
|
||||||
/*! Authentication challenge */
|
/*! Authentication challenge */
|
||||||
|
25
manager.c
25
manager.c
@@ -1326,8 +1326,11 @@ static int get_input(struct mansession *s, char *output)
|
|||||||
do {
|
do {
|
||||||
res = poll(fds, 1, -1);
|
res = poll(fds, 1, -1);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR) {
|
||||||
|
if (s->dead)
|
||||||
|
return -1;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
|
ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else if (res > 0) {
|
} else if (res > 0) {
|
||||||
@@ -1435,7 +1438,7 @@ static void *accept_thread(void *ignore)
|
|||||||
s->next = sessions;
|
s->next = sessions;
|
||||||
sessions = s;
|
sessions = s;
|
||||||
ast_mutex_unlock(&sessionlock);
|
ast_mutex_unlock(&sessionlock);
|
||||||
if (ast_pthread_create(&t, &attr, session_do, s))
|
if (ast_pthread_create(&s->t, &attr, session_do, s))
|
||||||
destroy_session(s);
|
destroy_session(s);
|
||||||
}
|
}
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
@@ -1468,13 +1471,11 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
struct mansession *s;
|
struct mansession *s;
|
||||||
char tmp[4096];
|
char tmp[4096];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
struct mansession *next, *prev = NULL;
|
|
||||||
|
|
||||||
ast_mutex_lock(&sessionlock);
|
ast_mutex_lock(&sessionlock);
|
||||||
s = sessions;
|
s = sessions;
|
||||||
while(s) {
|
while(s) {
|
||||||
next = s->next;
|
if (((s->readperm & category) == category) && ((s->send_events & category) == category)) {
|
||||||
if (((s->readperm & category) == category) && ((s->send_events & category) == category) ) {
|
|
||||||
ast_mutex_lock(&s->__lock);
|
ast_mutex_lock(&s->__lock);
|
||||||
ast_cli(s->fd, "Event: %s\r\n", event);
|
ast_cli(s->fd, "Event: %s\r\n", event);
|
||||||
ast_cli(s->fd, "Privilege: %s\r\n", authority_to_str(category, tmp, sizeof(tmp)));
|
ast_cli(s->fd, "Privilege: %s\r\n", authority_to_str(category, tmp, sizeof(tmp)));
|
||||||
@@ -1486,20 +1487,12 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||||||
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 manager session!\n");
|
||||||
/* Unlink from list */
|
s->dead = 1;
|
||||||
if (prev)
|
pthread_kill(s->t, SIGURG);
|
||||||
prev->next = next;
|
|
||||||
else
|
|
||||||
sessions = next;
|
|
||||||
ast_mutex_unlock(&s->__lock);
|
|
||||||
free_session(s);
|
|
||||||
s = next;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&s->__lock);
|
ast_mutex_unlock(&s->__lock);
|
||||||
}
|
}
|
||||||
prev = s;
|
s = s->next;
|
||||||
s = next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&sessionlock);
|
ast_mutex_unlock(&sessionlock);
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user