[Asterisk-cvs] asterisk manager.c,1.114,1.115

markster markster
Thu Sep 29 16:40:30 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv14998

Modified Files:
	manager.c 
Log Message:
Fix manager bug (can't destroy a session while a thread is using it!)


Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -d -r1.114 -r1.115
--- manager.c	28 Sep 2005 23:10:13 -0000	1.114
+++ manager.c	29 Sep 2005 20:37:01 -0000	1.115
@@ -1326,8 +1326,11 @@
 	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 @@
 		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 @@
 	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 @@
 				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;




More information about the svn-commits mailing list