diff --git a/include/asterisk.h b/include/asterisk.h index 08209bfb2d..4fcb5f8edd 100644 --- a/include/asterisk.h +++ b/include/asterisk.h @@ -75,6 +75,7 @@ void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */ int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */ void threadstorage_init(void); /*!< Provided by threadstorage.c */ int astobj2_init(void); /*! Provided by astobj2.c */ +void ast_autoservice_init(void); /*!< Provided by autoservice.c */ /* Many headers need 'ast_channel' to be defined */ struct ast_channel; diff --git a/main/asterisk.c b/main/asterisk.c index 52266b455a..51423bf553 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2896,6 +2896,8 @@ int main(int argc, char *argv[]) astobj2_init(); + ast_autoservice_init(); + if (load_modules(1)) { printf(term_quit()); exit(1); diff --git a/main/autoservice.c b/main/autoservice.c index 0a641e97c3..de14d82dd7 100644 --- a/main/autoservice.c +++ b/main/autoservice.c @@ -64,6 +64,7 @@ struct asent { }; static AST_LIST_HEAD_STATIC(aslist, asent); +static ast_cond_t as_cond; static pthread_t asthread = AST_PTHREADT_NULL; @@ -98,6 +99,9 @@ static void *autoservice_run(void *ign) * to get used again. */ as_chan_list_state++; + if (AST_LIST_EMPTY(&aslist)) + ast_cond_wait(&as_cond, &aslist.lock); + AST_LIST_TRAVERSE(&aslist, as, list) { if (!as->chan->_softhangup) { if (x < MAX_AUTOMONS) @@ -106,6 +110,7 @@ static void *autoservice_run(void *ign) ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events. Fix autoservice.c\n"); } } + AST_LIST_UNLOCK(&aslist); chan = ast_waitfor_n(mons, x, &ms); @@ -194,6 +199,8 @@ int ast_autoservice_start(struct ast_channel *chan) ast_channel_unlock(chan); AST_LIST_LOCK(&aslist); + if (AST_LIST_EMPTY(&aslist)) + ast_cond_signal(&as_cond); AST_LIST_INSERT_HEAD(&aslist, as, list); AST_LIST_UNLOCK(&aslist); @@ -276,3 +283,8 @@ int ast_autoservice_stop(struct ast_channel *chan) return res; } + +void ast_autoservice_init(void) +{ + ast_cond_init(&as_cond, NULL); +} diff --git a/main/channel.c b/main/channel.c index 53f48c8a41..16881a3d55 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1616,7 +1616,7 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int *exception, int *outfd, int *ms) { struct timeval start = { 0 , 0 }; - struct pollfd *pfds; + struct pollfd *pfds = NULL; int res; long rms; int x, y, max; @@ -1627,11 +1627,12 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, struct fdmap { int chan; int fdno; - } *fdmap; + } *fdmap = NULL; - sz = n * AST_MAX_FDS + nfds; - pfds = alloca(sizeof(*pfds) * sz); - fdmap = alloca(sizeof(*fdmap) * sz); + if ((sz = n * AST_MAX_FDS + nfds)) { + pfds = alloca(sizeof(*pfds) * sz); + fdmap = alloca(sizeof(*fdmap) * sz); + } if (outfd) *outfd = -99999;