mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
Occasionally, the alertpipe loses its nonblocking status, so detect and correct
that situation before it causes a deadlock. (Reported and tested by ctooley via #asterisk-dev) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@122130 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -758,6 +758,7 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
|
||||
if (needqueue) {
|
||||
if (pipe(tmp->alertpipe)) {
|
||||
ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
|
||||
alertpipe_failed:
|
||||
#ifdef HAVE_ZAPTEL
|
||||
if (tmp->timingfd > -1)
|
||||
close(tmp->timingfd);
|
||||
@@ -768,9 +769,19 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
|
||||
return NULL;
|
||||
} else {
|
||||
flags = fcntl(tmp->alertpipe[0], F_GETFL);
|
||||
fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK);
|
||||
if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
|
||||
close(tmp->alertpipe[0]);
|
||||
close(tmp->alertpipe[1]);
|
||||
goto alertpipe_failed;
|
||||
}
|
||||
flags = fcntl(tmp->alertpipe[1], F_GETFL);
|
||||
fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK);
|
||||
if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
|
||||
close(tmp->alertpipe[0]);
|
||||
close(tmp->alertpipe[1]);
|
||||
goto alertpipe_failed;
|
||||
}
|
||||
}
|
||||
} else /* Make sure we've got it done right if they don't */
|
||||
tmp->alertpipe[0] = tmp->alertpipe[1] = -1;
|
||||
@@ -1994,8 +2005,20 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
|
||||
|
||||
/* Read and ignore anything on the alertpipe, but read only
|
||||
one sizeof(blah) per frame that we send from it */
|
||||
if (chan->alertpipe[0] > -1)
|
||||
if (chan->alertpipe[0] > -1) {
|
||||
int flags = fcntl(chan->alertpipe[0], F_GETFL);
|
||||
/* For some odd reason, the alertpipe occasionally loses nonblocking status,
|
||||
* which immediately causes a deadlock scenario. Detect and prevent this. */
|
||||
if ((flags & O_NONBLOCK) == 0) {
|
||||
ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name);
|
||||
if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
|
||||
f = &ast_null_frame;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
read(chan->alertpipe[0], &blah, sizeof(blah));
|
||||
}
|
||||
|
||||
#ifdef HAVE_ZAPTEL
|
||||
if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
|
||||
|
Reference in New Issue
Block a user