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:
parent
8e4697d8f2
commit
2b883819be
|
@ -82,6 +82,8 @@ struct mansession {
|
|||
int fd;
|
||||
/*! Whether or not we're busy doing an action */
|
||||
int busy;
|
||||
/*! Whether or not we're "dead" */
|
||||
int dead;
|
||||
/*! Logged in username */
|
||||
char username[80];
|
||||
/*! Authentication challenge */
|
||||
|
|
25
manager.c
25
manager.c
|
@ -1326,8 +1326,11 @@ static int get_input(struct mansession *s, char *output)
|
|||
do {
|
||||
res = poll(fds, 1, -1);
|
||||
if (res < 0) {
|
||||
if (errno == EINTR)
|
||||
if (errno == EINTR) {
|
||||
if (s->dead)
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else if (res > 0) {
|
||||
|
@ -1435,7 +1438,7 @@ static void *accept_thread(void *ignore)
|
|||
s->next = sessions;
|
||||
sessions = s;
|
||||
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);
|
||||
}
|
||||
pthread_attr_destroy(&attr);
|
||||
|
@ -1468,13 +1471,11 @@ int manager_event(int category, char *event, char *fmt, ...)
|
|||
struct mansession *s;
|
||||
char tmp[4096];
|
||||
va_list ap;
|
||||
struct mansession *next, *prev = NULL;
|
||||
|
||||
ast_mutex_lock(&sessionlock);
|
||||
s = sessions;
|
||||
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_cli(s->fd, "Event: %s\r\n", event);
|
||||
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);
|
||||
} else if (ast_carefulwrite(s->fd,tmp,strlen(tmp),100) < 0) {
|
||||
ast_log(LOG_WARNING, "Disconnecting slow manager session!\n");
|
||||
/* Unlink from list */
|
||||
if (prev)
|
||||
prev->next = next;
|
||||
else
|
||||
sessions = next;
|
||||
ast_mutex_unlock(&s->__lock);
|
||||
free_session(s);
|
||||
s = next;
|
||||
continue;
|
||||
s->dead = 1;
|
||||
pthread_kill(s->t, SIGURG);
|
||||
}
|
||||
ast_mutex_unlock(&s->__lock);
|
||||
}
|
||||
prev = s;
|
||||
s = next;
|
||||
s = s->next;
|
||||
}
|
||||
ast_mutex_unlock(&sessionlock);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue