mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 04:46:29 +00:00
Fix race in local, update queue
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1143 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1156,6 +1156,46 @@ static int manager_queues_show( struct mansession *s, struct message *m )
|
|||||||
return queues_show( s->fd, 2, a );
|
return queues_show( s->fd, 2, a );
|
||||||
} /* /JDG */
|
} /* /JDG */
|
||||||
|
|
||||||
|
|
||||||
|
/* Dump queue status */
|
||||||
|
static int manager_queues_status( struct mansession *s, struct message *m )
|
||||||
|
{
|
||||||
|
time_t now;
|
||||||
|
int pos;
|
||||||
|
struct ast_call_queue *q;
|
||||||
|
struct queue_ent *qe;
|
||||||
|
astman_send_ack(s, "Queue status will follow");
|
||||||
|
time(&now);
|
||||||
|
q = queues;
|
||||||
|
while(q) {
|
||||||
|
ast_pthread_mutex_lock(&q->lock);
|
||||||
|
ast_cli(s->fd, "Event: QueueParams\r\n"
|
||||||
|
"Queue: %s\r\n"
|
||||||
|
"Max: %d\r\n"
|
||||||
|
"Calls: %d\r\n"
|
||||||
|
"\r\n",
|
||||||
|
q->name, q->maxlen, q->count);
|
||||||
|
#if 0
|
||||||
|
/* Do we care about queue members? */
|
||||||
|
for (mem = q->members; mem; mem = mem->next)
|
||||||
|
ast_cli(fd, " %s/%s\n", mem->tech, mem->loc);
|
||||||
|
#endif
|
||||||
|
pos = 1;
|
||||||
|
for (qe = q->head; qe; qe = qe->next)
|
||||||
|
ast_cli(s->fd, "Event: QueueMember\r\n"
|
||||||
|
"Queue: %s\r\n"
|
||||||
|
"Position: %d\r\n"
|
||||||
|
"Channel: %s\r\n"
|
||||||
|
"CallerID: %s\r\n"
|
||||||
|
"Wait: %ld\r\n"
|
||||||
|
"\r\n",
|
||||||
|
q->name, pos++, qe->chan->name, qe->chan->callerid ? qe->chan->callerid : "", now - qe->start);
|
||||||
|
ast_pthread_mutex_unlock(&q->lock);
|
||||||
|
q = q->next;
|
||||||
|
}
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static char show_queues_usage[] =
|
static char show_queues_usage[] =
|
||||||
"Usage: show queues\n"
|
"Usage: show queues\n"
|
||||||
" Provides summary information on call queues.\n";
|
" Provides summary information on call queues.\n";
|
||||||
@@ -1169,6 +1209,7 @@ int unload_module(void)
|
|||||||
STANDARD_HANGUP_LOCALUSERS;
|
STANDARD_HANGUP_LOCALUSERS;
|
||||||
ast_cli_unregister(&cli_show_queues);
|
ast_cli_unregister(&cli_show_queues);
|
||||||
ast_manager_unregister( "Queues" );
|
ast_manager_unregister( "Queues" );
|
||||||
|
ast_manager_unregister( "QueueStatus" );
|
||||||
return ast_unregister_application(app);
|
return ast_unregister_application(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1179,6 +1220,7 @@ int load_module(void)
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
ast_cli_register(&cli_show_queues);
|
ast_cli_register(&cli_show_queues);
|
||||||
ast_manager_register( "Queues", 0, manager_queues_show, "Queues" );
|
ast_manager_register( "Queues", 0, manager_queues_show, "Queues" );
|
||||||
|
ast_manager_register( "QueueStatus", 0, manager_queues_status, "Queue Status" );
|
||||||
|
|
||||||
// [PHM 06/26/03]
|
// [PHM 06/26/03]
|
||||||
ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;
|
ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;
|
||||||
|
@@ -61,6 +61,8 @@ static struct local_pvt {
|
|||||||
char context[AST_MAX_EXTENSION]; /* Context to call */
|
char context[AST_MAX_EXTENSION]; /* Context to call */
|
||||||
char exten[AST_MAX_EXTENSION]; /* Extension to call */
|
char exten[AST_MAX_EXTENSION]; /* Extension to call */
|
||||||
int reqformat; /* Requested format */
|
int reqformat; /* Requested format */
|
||||||
|
int glaredetect; /* Detect glare on hangup */
|
||||||
|
int cancelqueue; /* Cancel queue */
|
||||||
int alreadymasqed; /* Already masqueraded */
|
int alreadymasqed; /* Already masqueraded */
|
||||||
struct ast_channel *owner; /* Master Channel */
|
struct ast_channel *owner; /* Master Channel */
|
||||||
struct ast_channel *chan; /* Outbound channel */
|
struct ast_channel *chan; /* Outbound channel */
|
||||||
@@ -76,7 +78,15 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
|
|||||||
other = p->chan;
|
other = p->chan;
|
||||||
if (!other)
|
if (!other)
|
||||||
return 0;
|
return 0;
|
||||||
|
p->glaredetect = 1;
|
||||||
retrylock:
|
retrylock:
|
||||||
|
if (p->cancelqueue) {
|
||||||
|
/* We had a glare on the hangup. Forget all this business,
|
||||||
|
return and destroy p. */
|
||||||
|
ast_pthread_mutex_unlock(&p->lock);
|
||||||
|
free(p);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (pthread_mutex_trylock(&other->lock)) {
|
if (pthread_mutex_trylock(&other->lock)) {
|
||||||
/* Failed to lock. Release main lock and try again */
|
/* Failed to lock. Release main lock and try again */
|
||||||
ast_pthread_mutex_unlock(&p->lock);
|
ast_pthread_mutex_unlock(&p->lock);
|
||||||
@@ -87,6 +97,7 @@ retrylock:
|
|||||||
}
|
}
|
||||||
ast_queue_frame(other, f, 0);
|
ast_queue_frame(other, f, 0);
|
||||||
ast_pthread_mutex_unlock(&other->lock);
|
ast_pthread_mutex_unlock(&other->lock);
|
||||||
|
p->glaredetect = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +242,7 @@ static int local_hangup(struct ast_channel *ast)
|
|||||||
struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
|
struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
|
||||||
struct local_pvt *cur, *prev=NULL;
|
struct local_pvt *cur, *prev=NULL;
|
||||||
struct ast_channel *ochan = NULL;
|
struct ast_channel *ochan = NULL;
|
||||||
|
int glaredetect;
|
||||||
ast_pthread_mutex_lock(&p->lock);
|
ast_pthread_mutex_lock(&p->lock);
|
||||||
if (isoutbound)
|
if (isoutbound)
|
||||||
p->chan = NULL;
|
p->chan = NULL;
|
||||||
@@ -240,6 +252,11 @@ static int local_hangup(struct ast_channel *ast)
|
|||||||
|
|
||||||
if (!p->owner && !p->chan) {
|
if (!p->owner && !p->chan) {
|
||||||
/* Okay, done with the private part now, too. */
|
/* Okay, done with the private part now, too. */
|
||||||
|
glaredetect = p->glaredetect;
|
||||||
|
/* If we have a queue holding, don't actually destroy p yet, but
|
||||||
|
let local_queue do it. */
|
||||||
|
if (p->glaredetect)
|
||||||
|
p->cancelqueue = 1;
|
||||||
ast_pthread_mutex_unlock(&p->lock);
|
ast_pthread_mutex_unlock(&p->lock);
|
||||||
/* Remove from list */
|
/* Remove from list */
|
||||||
ast_pthread_mutex_lock(&locallock);
|
ast_pthread_mutex_lock(&locallock);
|
||||||
@@ -257,7 +274,8 @@ static int local_hangup(struct ast_channel *ast)
|
|||||||
}
|
}
|
||||||
ast_pthread_mutex_unlock(&locallock);
|
ast_pthread_mutex_unlock(&locallock);
|
||||||
/* And destroy */
|
/* And destroy */
|
||||||
free(p);
|
if (!glaredetect)
|
||||||
|
free(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (p->chan && !p->chan->pbx)
|
if (p->chan && !p->chan->pbx)
|
||||||
@@ -307,6 +325,7 @@ static struct local_pvt *local_alloc(char *data, int format)
|
|||||||
static struct ast_channel *local_new(struct local_pvt *p, int state)
|
static struct ast_channel *local_new(struct local_pvt *p, int state)
|
||||||
{
|
{
|
||||||
struct ast_channel *tmp, *tmp2;
|
struct ast_channel *tmp, *tmp2;
|
||||||
|
int randnum = rand() & 0xffff;
|
||||||
tmp = ast_channel_alloc(1);
|
tmp = ast_channel_alloc(1);
|
||||||
tmp2 = ast_channel_alloc(1);
|
tmp2 = ast_channel_alloc(1);
|
||||||
if (!tmp || !tmp2) {
|
if (!tmp || !tmp2) {
|
||||||
@@ -319,8 +338,8 @@ static struct ast_channel *local_new(struct local_pvt *p, int state)
|
|||||||
if (tmp) {
|
if (tmp) {
|
||||||
tmp->nativeformats = p->reqformat;
|
tmp->nativeformats = p->reqformat;
|
||||||
tmp2->nativeformats = p->reqformat;
|
tmp2->nativeformats = p->reqformat;
|
||||||
snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-1", p->exten, p->context);
|
snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-%04x.1", p->exten, p->context, randnum);
|
||||||
snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-2", p->exten, p->context);
|
snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-%04x,2", p->exten, p->context, randnum);
|
||||||
tmp->type = type;
|
tmp->type = type;
|
||||||
tmp2->type = type;
|
tmp2->type = type;
|
||||||
ast_setstate(tmp, state);
|
ast_setstate(tmp, state);
|
||||||
|
Reference in New Issue
Block a user