mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 20:44:20 +00:00
backport proper channel_find_locked behavior from 1.4 branch (noted by Steve Davies on asterisk-dev list)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@47802 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
41
channel.c
41
channel.c
@@ -732,44 +732,35 @@ static struct ast_channel *channel_find_locked(const struct ast_channel *prev,
|
||||
const char *context, const char *exten)
|
||||
{
|
||||
const char *msg = prev ? "deadlock" : "initial deadlock";
|
||||
int retries, done;
|
||||
int retries;
|
||||
struct ast_channel *c;
|
||||
|
||||
for (retries = 0; retries < 10; retries++) {
|
||||
int done;
|
||||
|
||||
ast_mutex_lock(&chlock);
|
||||
for (c = channels; c; c = c->next) {
|
||||
if (!prev) {
|
||||
/* want head of list */
|
||||
if (!name && !exten)
|
||||
break;
|
||||
if (name) {
|
||||
/* want match by full name */
|
||||
if (!namelen) {
|
||||
if (!strcasecmp(c->name, name))
|
||||
break;
|
||||
else
|
||||
if (prev) { /* look for next item */
|
||||
if (c != prev) /* not this one */
|
||||
continue;
|
||||
/* found, prepare to return c->next */
|
||||
c = c->next;
|
||||
}
|
||||
/* want match by name prefix */
|
||||
if (!strncasecmp(c->name, name, namelen))
|
||||
break;
|
||||
if (name) { /* want match by name */
|
||||
if ((!namelen && strcasecmp(c->name, name)) ||
|
||||
(namelen && strncasecmp(c->name, name, namelen)))
|
||||
continue; /* name match failed */
|
||||
} else if (exten) {
|
||||
/* want match by context and exten */
|
||||
if (context && (strcasecmp(c->context, context) &&
|
||||
strcasecmp(c->macrocontext, context)))
|
||||
continue;
|
||||
/* match by exten */
|
||||
if (context && strcasecmp(c->context, context) &&
|
||||
strcasecmp(c->macrocontext, context))
|
||||
continue; /* context match failed */
|
||||
if (strcasecmp(c->exten, exten) &&
|
||||
strcasecmp(c->macroexten, exten))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
continue; /* exten match failed */
|
||||
}
|
||||
} else if (c == prev) { /* found, return c->next */
|
||||
c = c->next;
|
||||
/* if we get here, c points to the desired record */
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* exit if chan not found or mutex acquired successfully */
|
||||
done = (c == NULL) || (ast_mutex_trylock(&c->lock) == 0);
|
||||
/* this is slightly unsafe, as we _should_ hold the lock to access c->name */
|
||||
|
Reference in New Issue
Block a user