[asterisk-commits] russell: branch 1.4 r101414 - /branches/1.4/channels/chan_agent.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 31 13:07:46 CST 2008


Author: russell
Date: Thu Jan 31 13:07:46 2008
New Revision: 101414

URL: http://svn.digium.com/view/asterisk?view=rev&rev=101414
Log:
Move the locking from find_agent() into the agent dialplan function handler to
ensure that the agent doesn't disappear while we're looking at it.

Modified:
    branches/1.4/channels/chan_agent.c

Modified: branches/1.4/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_agent.c?view=diff&rev=101414&r1=101413&r2=101414
==============================================================================
--- branches/1.4/channels/chan_agent.c (original)
+++ branches/1.4/channels/chan_agent.c Thu Jan 31 13:07:46 2008
@@ -2568,16 +2568,17 @@
 	return res;
 }
 
+/*!
+ * \note This function expects the agent list to be locked
+ */
 static struct agent_pvt *find_agent(char *agentid)
 {
 	struct agent_pvt *cur;
 
-	AST_LIST_LOCK(&agents);
 	AST_LIST_TRAVERSE(&agents, cur, list) {
 		if (!strcmp(cur->agent, agentid))
 			break;	
 	}
-	AST_LIST_UNLOCK(&agents);
 
 	return cur;	
 }
@@ -2605,7 +2606,10 @@
 	if (!args.item)
 		args.item = "status";
 
+	AST_LIST_LOCK(&agents);
+
 	if (!(agent = find_agent(args.agentid))) {
+		AST_LIST_UNLOCK(&agents);
 		ast_log(LOG_WARNING, "Agent '%s' not found!\n", args.agentid);
 		return -1;
 	}
@@ -2630,6 +2634,8 @@
 		} 
 	} else if (!strcasecmp(args.item, "exten"))
 		ast_copy_string(buf, agent->loginchan, len);	
+
+	AST_LIST_UNLOCK(&agents);
 
 	return 0;
 }




More information about the asterisk-commits mailing list