]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Move the locking from find_agent() into the agent dialplan function handler to
authorRussell Bryant <russell@russellbryant.com>
Thu, 31 Jan 2008 19:07:46 +0000 (19:07 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 31 Jan 2008 19:07:46 +0000 (19:07 +0000)
ensure that the agent doesn't disappear while we're looking at it.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@101414 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c

index 4163072b692d47be2143153c14c9e00911cd4974..036090166d2eb51c0c449728f38e6c38d407210d 100644 (file)
@@ -2568,16 +2568,17 @@ static int agent_devicestate(void *data)
        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 @@ static int function_agent(struct ast_channel *chan, char *cmd, char *data, char
        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;
        }
@@ -2631,6 +2635,8 @@ static int function_agent(struct ast_channel *chan, char *cmd, char *data, char
        } else if (!strcasecmp(args.item, "exten"))
                ast_copy_string(buf, agent->loginchan, len);    
 
+       AST_LIST_UNLOCK(&agents);
+
        return 0;
 }