mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 11:28:25 +00:00
chan_agent: Fix agent_indicate() locking.
Avoid deadlock potential with local channels and simplify the locking. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@378427 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -784,23 +784,19 @@ static int agent_indicate(struct ast_channel *ast, int condition, const void *da
|
|||||||
{
|
{
|
||||||
struct agent_pvt *p = ast->tech_pvt;
|
struct agent_pvt *p = ast->tech_pvt;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
ast_mutex_lock(&p->lock);
|
ast_mutex_lock(&p->lock);
|
||||||
if (p->chan && !ast_check_hangup(p->chan)) {
|
if (p->chan && !ast_check_hangup(p->chan)) {
|
||||||
while (ast_channel_trylock(p->chan)) {
|
ast_channel_unlock(ast);
|
||||||
int res;
|
ast_channel_lock(p->chan);
|
||||||
if ((res = ast_channel_unlock(ast))) {
|
|
||||||
ast_log(LOG_ERROR, "chan_agent bug! Channel was not locked upon entry to agent_indicate: %s\n", res > 0 ? strerror(res) : "Bad ao2obj data");
|
|
||||||
ast_mutex_unlock(&p->lock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
usleep(1);
|
|
||||||
ast_channel_lock(ast);
|
|
||||||
}
|
|
||||||
res = p->chan->tech->indicate ? p->chan->tech->indicate(p->chan, condition, data, datalen) : -1;
|
res = p->chan->tech->indicate ? p->chan->tech->indicate(p->chan, condition, data, datalen) : -1;
|
||||||
ast_channel_unlock(p->chan);
|
ast_channel_unlock(p->chan);
|
||||||
} else
|
ast_mutex_unlock(&p->lock);
|
||||||
|
ast_channel_lock(ast);
|
||||||
|
} else {
|
||||||
|
ast_mutex_unlock(&p->lock);
|
||||||
res = 0;
|
res = 0;
|
||||||
ast_mutex_unlock(&p->lock);
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user