]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Add more missing locking of the agents list ...
authorRussell Bryant <russell@russellbryant.com>
Thu, 31 Jan 2008 19:17:05 +0000 (19:17 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 31 Jan 2008 19:17:05 +0000 (19:17 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@101433 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c

index 036090166d2eb51c0c449728f38e6c38d407210d..08a29a7d60edd21c83f9be8f53244ae3dfca71ea 100644 (file)
@@ -1571,6 +1571,7 @@ static int agent_logoff(const char *agent, int soft)
        long logintime;
        int ret = -1; /* Return -1 if no agent if found */
 
+       AST_LIST_LOCK(&agents);
        AST_LIST_TRAVERSE(&agents, p, list) {
                if (!strcasecmp(p->agent, agent)) {
                        ret = 0;
@@ -1590,6 +1591,7 @@ static int agent_logoff(const char *agent, int soft)
                        break;
                }
        }
+       AST_LIST_UNLOCK(&agents);
 
        return ret;
 }
@@ -1644,20 +1646,26 @@ static int action_agent_logoff(struct mansession *s, const struct message *m)
 
 static char *complete_agent_logoff_cmd(const char *line, const char *word, int pos, int state)
 {
+       char *ret = NULL;
+
        if (pos == 2) {
                struct agent_pvt *p;
                char name[AST_MAX_AGENT];
                int which = 0, len = strlen(word);
 
+               AST_LIST_LOCK(&agents);
                AST_LIST_TRAVERSE(&agents, p, list) {
                        snprintf(name, sizeof(name), "Agent/%s", p->agent);
-                       if (!strncasecmp(word, name, len) && ++which > state)
-                               return ast_strdup(name);
+                       if (!strncasecmp(word, name, len) && ++which > state) {
+                               ret = ast_strdup(name);
+                               break;
+                       }
                }
+               AST_LIST_UNLOCK(&agents);
        } else if (pos == 3 && state == 0) 
                return ast_strdup("soft");
        
-       return NULL;
+       return ret;
 }
 
 /*!