Index: main/channel.c =================================================================== --- main/channel.c (revision 121861) +++ main/channel.c (working copy) @@ -768,9 +768,29 @@ 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, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); +#ifdef HAVE_ZAPTEL + if (tmp->timingfd > -1) + close(tmp->timingfd); +#endif + sched_context_destroy(tmp->sched); + ast_string_field_free_memory(tmp); + free(tmp); + return NULL; + } 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, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); +#ifdef HAVE_ZAPTEL + if (tmp->timingfd > -1) + close(tmp->timingfd); +#endif + sched_context_destroy(tmp->sched); + ast_string_field_free_memory(tmp); + free(tmp); + return NULL; + } } } else /* Make sure we've got it done right if they don't */ tmp->alertpipe[0] = tmp->alertpipe[1] = -1; @@ -1994,8 +2014,18 @@ /* 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); + 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)) {