[asterisk-commits] russell: branch 1.4 r51781 - /branches/1.4/main/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 23 15:04:02 MST 2007


Author: russell
Date: Tue Jan 23 16:04:01 2007
New Revision: 51781

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51781
Log:
Fix some bugs in process_message().  The manager session lock needs to be held
when sending some sort of response, or calling one of the manager action
callbacks.  This resolves an issue where people using the GUI would get random
crashes when they start clicking around a lot.
(issue #8711, reported and debugged by zandbelt)

Modified:
    branches/1.4/main/manager.c

Modified: branches/1.4/main/manager.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/manager.c?view=diff&rev=51781&r1=51780&r2=51781
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Tue Jan 23 16:04:01 2007
@@ -1966,7 +1966,9 @@
 	ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
 
 	if (ast_strlen_zero(action)) {
+		ast_mutex_lock(&s->__lock);
 		astman_send_error(s, m, "Missing action in request");
+		ast_mutex_unlock(&s->__lock);
 		return 0;
 	}
 	if (!ast_strlen_zero(id)) {
@@ -1987,13 +1989,17 @@
 				ast_mutex_unlock(&s->__lock);
 				return 0;
 			} else {
+				ast_mutex_lock(&s->__lock);
 				astman_send_error(s, m, "Must specify AuthType");
+				ast_mutex_unlock(&s->__lock);
 				return 0;
 			}
 		} else if (!strcasecmp(action, "Login")) {
 			if (authenticate(s, m)) {
 				sleep(1);
+				ast_mutex_lock(&s->__lock);
 				astman_send_error(s, m, "Authentication failed");
+				ast_mutex_unlock(&s->__lock);
 				return -1;
 			} else {
 				s->authenticated = 1;
@@ -2003,10 +2009,14 @@
 					}
 				}
 				ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr));
+				ast_mutex_lock(&s->__lock);
 				astman_send_ack(s, m, "Authentication accepted");
+				ast_mutex_unlock(&s->__lock);
 			}
 		} else if (!strcasecmp(action, "Logoff")) {
+			ast_mutex_lock(&s->__lock);
 			astman_send_ack(s, m, "See ya");
+			ast_mutex_unlock(&s->__lock);
 			return -1;
 		} else
 			astman_send_error(s, m, "Authentication Required");
@@ -2015,11 +2025,13 @@
 		for (tmp = first_action; tmp; tmp = tmp->next) { 		
 			if (strcasecmp(action, tmp->action))
 				continue;
+			ast_mutex_lock(&s->__lock);
 			if ((s->writeperm & tmp->authority) == tmp->authority) {
 				if (tmp->func(s, m))
 					ret = -1;
 			} else
 				astman_send_error(s, m, "Permission denied");
+			ast_mutex_unlock(&s->__lock);
 			break;
 		}
 		ast_mutex_unlock(&actionlock);



More information about the asterisk-commits mailing list