diff options
author | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-09-09 20:06:31 +0000 |
---|---|---|
committer | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-09-09 20:06:31 +0000 |
commit | bbdc6cafb5a4c952b565135ee3470200673b310f (patch) | |
tree | bf8e77f6e4f2525aaca5cf79d01143c9973cdbd2 /main | |
parent | 994debde3c3d78011509a53fc68dd6ae27a6024e (diff) |
Transmit silence when reading DTMF in ast_readstring.
Otherwise, you could get issues with DTMF timeouts causing hangups.
(closes issue #17370)
Reported by: makoto
Patches:
channel-readstring-silence-generator.patch uploaded by makoto (license 38)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@285742 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 45 | ||||
-rw-r--r-- | main/channel.c | 27 | ||||
-rw-r--r-- | main/config.c | 2 | ||||
-rw-r--r-- | main/manager.c | 28 | ||||
-rw-r--r-- | main/pbx.c | 14 | ||||
-rw-r--r-- | main/poll.c | 355 |
6 files changed, 278 insertions, 193 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index c62447089..44051b514 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2009, Digium, Inc. + * Copyright (C) 1999 - 2010, Digium, Inc. * * Mark Spencer <markster@digium.com> * @@ -161,7 +161,6 @@ int option_debug; /*!< Debug level */ double option_maxload; /*!< Max load avg on system */ int option_maxcalls; /*!< Max number of active calls */ - /*! @} */ char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR; @@ -240,6 +239,8 @@ extern const char *ast_build_os; extern const char *ast_build_date; extern const char *ast_build_user; +unsigned int ast_FD_SETSIZE = FD_SETSIZE; + static char *_argv[256]; static int shuttingdown; static int restartnow; @@ -2734,6 +2735,7 @@ int main(int argc, char *argv[]) int isroot = 1, rundir_exists = 0; char *buf; char *runuser = NULL, *rungroup = NULL; + struct rlimit l; /* Remember original args for restart */ if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) { @@ -2882,7 +2884,6 @@ int main(int argc, char *argv[]) } if (ast_opt_dump_core) { - struct rlimit l; memset(&l, 0, sizeof(l)); l.rlim_cur = RLIM_INFINITY; l.rlim_max = RLIM_INFINITY; @@ -2891,6 +2892,44 @@ int main(int argc, char *argv[]) } } + if (getrlimit(RLIMIT_NOFILE, &l)) { + ast_log(LOG_WARNING, "Unable to check file descriptor limit: %s\n", strerror(errno)); + } + +#if !defined(CONFIGURE_RAN_AS_ROOT) + /* Check if select(2) will run with more file descriptors */ + do { + int fd, fd2; + ast_fdset readers; + struct timeval tv = { 0, }; + + if (l.rlim_cur <= FD_SETSIZE) { + /* The limit of select()able FDs is irrelevant, because we'll never + * open one that high. */ + break; + } + + if (!(fd = open("/dev/null", O_RDONLY))) { + ast_log(LOG_ERROR, "Cannot open a file descriptor at boot? %s\n", strerror(errno)); + break; /* XXX Should we exit() here? XXX */ + } + + fd2 = (l.rlim_cur > sizeof(readers) * 8 ? sizeof(readers) * 8 : l.rlim_cur) - 1; + if (dup2(fd, fd2)) { + ast_log(LOG_WARNING, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno)); + break; + } + + FD_ZERO(&readers); + FD_SET(fd2, &readers); + if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) { + ast_log(LOG_WARNING, "Maximum select()able file descriptor is %d\n", FD_SETSIZE); + } + } while (0); +#elif defined(HAVE_VARIABLE_FDSET) + ast_FD_SETSIZE = l.rlim_cur; +#endif /* !defined(CONFIGURE_RAN_AS_ROOT) */ + if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP)) rungroup = ast_config_AST_RUN_GROUP; if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER)) diff --git a/main/channel.c b/main/channel.c index 1d28515c6..2d6fb845b 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3722,6 +3722,8 @@ int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, in int pos = 0; /* index in the buffer where we accumulate digits */ int to = ftimeout; + struct ast_silence_generator *silgen = NULL; + /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) return -1; @@ -3732,26 +3734,35 @@ int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, in if (c->stream) { d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); ast_stopstream(c); + if (!silgen && ast_opt_transmit_silence) + silgen = ast_channel_start_silence_generator(c); usleep(1000); if (!d) d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); } else { + if (!silgen && ast_opt_transmit_silence) + silgen = ast_channel_start_silence_generator(c); d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); } - if (d < 0) + if (d < 0) { + ast_channel_stop_silence_generator(c, silgen); return -1; + } if (d == 0) { s[pos]='\0'; + ast_channel_stop_silence_generator(c, silgen); return 1; } if (d == 1) { s[pos]='\0'; + ast_channel_stop_silence_generator(c, silgen); return 2; } if (!strchr(enders, d)) s[pos++] = d; if (strchr(enders, d) || (pos >= len)) { s[pos]='\0'; + ast_channel_stop_silence_generator(c, silgen); return 0; } to = timeout; @@ -4032,6 +4043,7 @@ int ast_do_masquerade(struct ast_channel *original) void *t_pvt; struct ast_callerid tmpcid; struct ast_channel *clone = original->masq; + struct ast_channel *bridged; struct ast_cdr *cdr; int rformat = original->readformat; int wformat = original->writeformat; @@ -4298,6 +4310,15 @@ int ast_do_masquerade(struct ast_channel *original) pthread_kill(original->blocker, SIGURG); if (option_debug) ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state); + + if ((bridged = ast_bridged_channel(original))) { + ast_channel_lock(bridged); + ast_indicate(bridged, AST_CONTROL_SRCCHANGE); + ast_channel_unlock(bridged); + } + + ast_indicate(original, AST_CONTROL_SRCCHANGE); + return 0; } @@ -4679,8 +4700,8 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); /* Before we enter in and bridge these two together tell them both the source of audio has changed */ - ast_indicate(c0, AST_CONTROL_SRCUPDATE); - ast_indicate(c1, AST_CONTROL_SRCUPDATE); + ast_indicate(c0, AST_CONTROL_SRCCHANGE); + ast_indicate(c1, AST_CONTROL_SRCCHANGE); for (/* ever */;;) { struct timeval now = { 0, }; diff --git a/main/config.c b/main/config.c index f2b738c69..b1aa9e56f 100644 --- a/main/config.c +++ b/main/config.c @@ -222,7 +222,7 @@ void ast_variables_destroy(struct ast_variable *v) v = v->next; ast_destroy_comment(&vn->precomments); ast_destroy_comment(&vn->sameline); - free(vn); + ast_free(vn); } } diff --git a/main/manager.c b/main/manager.c index 42bac53cd..fb4c8139e 100644 --- a/main/manager.c +++ b/main/manager.c @@ -97,13 +97,22 @@ struct eventqent { char eventdata[1]; }; +static const int DEFAULT_ENABLED = 0; /*!< Default setting for manager to be enabled */ +static const int DEFAULT_WEBENABLED = 0; /*!< Default setting for the web interface to be enabled */ +static const int DEFAULT_BLOCKSOCKETS = 0; /*!< Default setting for block-sockets */ +static const int DEFAULT_DISPLAYCONNECTS = 1; /*!< Default setting for displaying manager connections */ +static const int DEFAULT_TIMESTAMPEVENTS = 0; /*!< Default setting for timestampevents */ +static const int DEFAULT_HTTPTIMEOUT = 60; /*!< Default manager http timeout */ +static const int DEFAULT_BROKENEVENTSACTION = 0; /*!< Default setting for brokeneventsaction */ + + static int enabled; static int portno = DEFAULT_MANAGER_PORT; static int asock = -1; -static int displayconnects = 1; +static int displayconnects; static int timestampevents; -static int httptimeout = 60; -static int broken_events_action = 0; +static int httptimeout; +static int broken_events_action; static pthread_t t; static int block_sockets; @@ -3053,8 +3062,8 @@ int init_manager(void) static struct sockaddr_in ba; int x = 1; int flags; - int webenabled = 0; - int newhttptimeout = 60; + int webenabled = DEFAULT_WEBENABLED; + int newhttptimeout = DEFAULT_HTTPTIMEOUT; struct ast_manager_user *user = NULL; if (!registered) { @@ -3085,9 +3094,14 @@ int init_manager(void) /* Append placeholder event so master_eventq never runs dry */ append_event("Event: Placeholder\r\n\r\n", 0); } + portno = DEFAULT_MANAGER_PORT; - displayconnects = 1; - broken_events_action = 0; + displayconnects = DEFAULT_DISPLAYCONNECTS; + broken_events_action = DEFAULT_BROKENEVENTSACTION; + block_sockets = DEFAULT_BLOCKSOCKETS; + timestampevents = DEFAULT_TIMESTAMPEVENTS; + httptimeout = DEFAULT_HTTPTIMEOUT; + cfg = ast_config_load("manager.conf"); if (!cfg) { ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n"); diff --git a/main/pbx.c b/main/pbx.c index 1ad2d2e1d..e88bdb879 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -492,7 +492,11 @@ static struct pbx_builtin { }; static struct ast_context *contexts; -AST_RWLOCK_DEFINE_STATIC(conlock); /*!< Lock for the ast_context list */ +/*!\brief Lock for the ast_context list + * This lock MUST be recursive, or a deadlock on reload may result. See + * https://issues.asterisk.org/view.php?id=17643 + */ +AST_MUTEX_DEFINE_STATIC(conlock); static AST_LIST_HEAD_STATIC(apps, ast_app); @@ -6193,22 +6197,22 @@ int load_pbx(void) */ int ast_lock_contexts() { - return ast_rwlock_wrlock(&conlock); + return ast_mutex_lock(&conlock); } int ast_rdlock_contexts(void) { - return ast_rwlock_rdlock(&conlock); + return ast_mutex_lock(&conlock); } int ast_wrlock_contexts(void) { - return ast_rwlock_wrlock(&conlock); + return ast_mutex_lock(&conlock); } int ast_unlock_contexts() { - return ast_rwlock_unlock(&conlock); + return ast_mutex_unlock(&conlock); } /* diff --git a/main/poll.c b/main/poll.c index aba6e593e..d9151c016 100644 --- a/main/poll.c +++ b/main/poll.c @@ -10,9 +10,9 @@ struct pollfd { - int fd; - short events; - short revents; + int fd; + short events; + short revents; } int poll (struct pollfd *pArray, unsigned long n_fds, int timeout) @@ -73,15 +73,14 @@ #include "asterisk.h" -#include <unistd.h> /* standard Unix definitions */ -#include <sys/types.h> /* system types */ -#include <sys/time.h> /* time definitions */ -#include <assert.h> /* assertion macros */ -#include <string.h> /* string functions */ +#include <unistd.h> /* standard Unix definitions */ +#include <sys/types.h> /* system types */ +#include <sys/time.h> /* time definitions */ +#include <assert.h> /* assertion macros */ +#include <string.h> /* string functions */ +#include <errno.h> -#include "asterisk/poll-compat.h" /* this package */ - -#ifdef AST_POLL_COMPAT +#include "asterisk/poll-compat.h" /* this package */ /*---------------------------------------------------------------------------*\ Macros @@ -92,210 +91,218 @@ #endif /*---------------------------------------------------------------------------*\ - Private Functions + Private Functions \*---------------------------------------------------------------------------*/ -static int map_poll_spec -#if __STDC__ > 0 - (struct pollfd *pArray, - unsigned long n_fds, - fd_set *pReadSet, - fd_set *pWriteSet, - fd_set *pExceptSet) -#else - (pArray, n_fds, pReadSet, pWriteSet, pExceptSet) - struct pollfd *pArray; - unsigned long n_fds; - fd_set *pReadSet; - fd_set *pWriteSet; - fd_set *pExceptSet; -#endif +#if defined(AST_POLL_COMPAT) +static int map_poll_spec(struct pollfd *pArray, unsigned long n_fds, + ast_fdset *pReadSet, ast_fdset *pWriteSet, ast_fdset *pExceptSet) { - register unsigned long i; /* loop control */ - register struct pollfd *pCur; /* current array element */ - register int max_fd = -1; /* return value */ - - /* - Map the poll() structures into the file descriptor sets required - by select(). - */ - for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) - { - /* Skip any bad FDs in the array. */ - - if (pCur->fd < 0) - continue; - - if (pCur->events & POLLIN) - { - /* "Input Ready" notification desired. */ - FD_SET (pCur->fd, pReadSet); + register unsigned long i; /* loop control */ + register struct pollfd *pCur; /* current array element */ + register int max_fd = -1; /* return value */ + + /* + * Map the poll() structures into the file descriptor sets required + * by select(). + */ + for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) { + /* Skip any bad FDs in the array. */ + + if (pCur->fd < 0) { + continue; + } + + if (pCur->events & POLLIN) { + /* "Input Ready" notification desired. */ + FD_SET(pCur->fd, pReadSet); + } + + if (pCur->events & POLLOUT) { + /* "Output Possible" notification desired. */ + FD_SET(pCur->fd, pWriteSet); + } + + if (pCur->events & POLLPRI) { + /* + * "Exception Occurred" notification desired. (Exceptions + * include out of band data. + */ + FD_SET(pCur->fd, pExceptSet); + } + + max_fd = MAX(max_fd, pCur->fd); } - if (pCur->events & POLLOUT) - { - /* "Output Possible" notification desired. */ - FD_SET (pCur->fd, pWriteSet); - } - - if (pCur->events & POLLPRI) - { - /* - "Exception Occurred" notification desired. (Exceptions - include out of band data. - */ - FD_SET (pCur->fd, pExceptSet); - } - - max_fd = MAX (max_fd, pCur->fd); - } - - return max_fd; + return max_fd; } - -static struct timeval *map_timeout -#if __STDC__ > 0 - (int poll_timeout, struct timeval *pSelTimeout) -#else - (poll_timeout, pSelTimeout) - int poll_timeout; - struct timeval *pSelTimeout; -#endif + +#ifdef AST_POLL_COMPAT +static struct timeval *map_timeout(int poll_timeout, struct timeval *pSelTimeout) { - struct timeval *pResult; + struct timeval *pResult; - /* - Map the poll() timeout value into a select() timeout. The possible - values of the poll() timeout value, and their meanings, are: + /* + Map the poll() timeout value into a select() timeout. The possible + values of the poll() timeout value, and their meanings, are: - VALUE MEANING + VALUE MEANING - -1 wait indefinitely (until signal occurs) - 0 return immediately, don't block - >0 wait specified number of milliseconds + -1 wait indefinitely (until signal occurs) + 0 return immediately, don't block + >0 wait specified number of milliseconds - select() uses a "struct timeval", which specifies the timeout in - seconds and microseconds, so the milliseconds value has to be mapped - accordingly. - */ + select() uses a "struct timeval", which specifies the timeout in + seconds and microseconds, so the milliseconds value has to be mapped + accordingly. + */ - assert (pSelTimeout != (struct timeval *) NULL); + assert(pSelTimeout != NULL); - switch (poll_timeout) - { + switch (poll_timeout) { case -1: - /* - A NULL timeout structure tells select() to wait indefinitely. - */ - pResult = (struct timeval *) NULL; - break; + /* + * A NULL timeout structure tells select() to wait indefinitely. + */ + pResult = (struct timeval *) NULL; + break; case 0: - /* - "Return immediately" (test) is specified by all zeros in - a timeval structure. - */ - pSelTimeout->tv_sec = 0; - pSelTimeout->tv_usec = 0; - pResult = pSelTimeout; - break; + /* + * "Return immediately" (test) is specified by all zeros in + * a timeval structure. + */ + pSelTimeout->tv_sec = 0; + pSelTimeout->tv_usec = 0; + pResult = pSelTimeout; + break; default: - /* Wait the specified number of milliseconds. */ - pSelTimeout->tv_sec = poll_timeout / 1000; /* get seconds */ - poll_timeout %= 1000; /* remove seconds */ - pSelTimeout->tv_usec = poll_timeout * 1000; /* get microseconds */ - pResult = pSelTimeout; - break; - } - + /* Wait the specified number of milliseconds. */ + pSelTimeout->tv_sec = poll_timeout / 1000; /* get seconds */ + poll_timeout %= 1000; /* remove seconds */ + pSelTimeout->tv_usec = poll_timeout * 1000; /* get microseconds */ + pResult = pSelTimeout; + break; + } - return pResult; + return pResult; } +#endif /* AST_POLL_COMPAT */ -static void map_select_results -#if __STDC__ > 0 - (struct pollfd *pArray, - unsigned long n_fds, - fd_set *pReadSet, - fd_set *pWriteSet, - fd_set *pExceptSet) -#else - (pArray, n_fds, pReadSet, pWriteSet, pExceptSet) - struct pollfd *pArray; - unsigned long n_fds; - fd_set *pReadSet; - fd_set *pWriteSet; - fd_set *pExceptSet; -#endif +static void map_select_results(struct pollfd *pArray, unsigned long n_fds, + ast_fdset *pReadSet, ast_fdset *pWriteSet, ast_fdset *pExceptSet) { - register unsigned long i; /* loop control */ - register struct pollfd *pCur; /* current array element */ - - for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) - { - /* Skip any bad FDs in the array. */ - - if (pCur->fd < 0) - continue; - - /* Exception events take priority over input events. */ - - pCur->revents = 0; - if (FD_ISSET (pCur->fd, pExceptSet)) - pCur->revents |= POLLPRI; - - else if (FD_ISSET (pCur->fd, pReadSet)) - pCur->revents |= POLLIN; - - if (FD_ISSET (pCur->fd, pWriteSet)) - pCur->revents |= POLLOUT; - } + register unsigned long i; /* loop control */ + register struct pollfd *pCur; /* current array element */ + + for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) { + /* Skip any bad FDs in the array. */ + + if (pCur->fd < 0) { + continue; + } + + /* Exception events take priority over input events. */ + pCur->revents = 0; + if (FD_ISSET(pCur->fd, (fd_set *) pExceptSet)) { + pCur->revents |= POLLPRI; + } else if (FD_ISSET(pCur->fd, (fd_set *) pReadSet)) { + pCur->revents |= POLLIN; + } + + if (FD_ISSET(pCur->fd, (fd_set *) pWriteSet)) { + pCur->revents |= POLLOUT; + } + } - return; + return; } +#endif /* defined(AST_POLL_COMPAT) || !defined(HAVE_PPOLL) */ /*---------------------------------------------------------------------------*\ - Public Functions + Public Functions \*---------------------------------------------------------------------------*/ - +#ifdef AST_POLL_COMPAT int ast_internal_poll(struct pollfd *pArray, unsigned long n_fds, int timeout) { - fd_set read_descs; /* input file descs */ - fd_set write_descs; /* output file descs */ - fd_set except_descs; /* exception descs */ - struct timeval stime; /* select() timeout value */ - int ready_descriptors; /* function result */ - int max_fd = 0; /* maximum fd value */ - struct timeval *pTimeout; /* actually passed */ + ast_fdset read_descs; /* input file descs */ + ast_fdset write_descs; /* output file descs */ + ast_fdset except_descs; /* exception descs */ + struct timeval stime; /* select() timeout value */ + int ready_descriptors; /* function result */ + int max_fd = 0; /* maximum fd value */ + struct timeval *pTimeout; /* actually passed */ + int save_errno; - FD_ZERO (&read_descs); - FD_ZERO (&write_descs); - FD_ZERO (&except_descs); + FD_ZERO(&read_descs); + FD_ZERO(&write_descs); + FD_ZERO(&except_descs); - /* Map the poll() file descriptor list in the select() data structures. */ + /* Map the poll() file descriptor list in the select() data structures. */ if (pArray) { - max_fd = map_poll_spec (pArray, n_fds, + max_fd = map_poll_spec (pArray, n_fds, &read_descs, &write_descs, &except_descs); } - /* Map the poll() timeout value in the select() timeout structure. */ + /* Map the poll() timeout value in the select() timeout structure. */ - pTimeout = map_timeout (timeout, &stime); + pTimeout = map_timeout (timeout, &stime); - /* Make the select() call. */ + /* Make the select() call. */ - ready_descriptors = select (max_fd + 1, &read_descs, &write_descs, + ready_descriptors = ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, pTimeout); + save_errno = errno; - if (ready_descriptors >= 0) - { - map_select_results (pArray, n_fds, - &read_descs, &write_descs, &except_descs); - } + if (ready_descriptors >= 0) { + map_select_results (pArray, n_fds, + &read_descs, &write_descs, &except_descs); + } - return ready_descriptors; + errno = save_errno; + return ready_descriptors; } - #endif /* AST_POLL_COMPAT */ + +int ast_poll2(struct pollfd *pArray, unsigned long n_fds, struct timeval *tv) +{ +#if !defined(AST_POLL_COMPAT) + struct timeval start = ast_tvnow(); +#if defined(HAVE_PPOLL) + struct timespec ts = { tv ? tv->tv_sec : 0, tv ? tv->tv_usec * 1000 : 0 }; + int res = ppoll(pArray, n_fds, tv ? &ts : NULL, NULL); +#else + int res = poll(pArray, n_fds, tv ? tv->tv_sec * 1000 + tv->tv_usec / 1000 : -1); +#endif + struct timeval after = ast_tvnow(); + if (res > 0 && tv && ast_tvdiff_ms(ast_tvadd(*tv, start), after) > 0) { + *tv = ast_tvsub(*tv, ast_tvsub(after, start)); + } else if (res > 0 && tv) { + *tv = ast_tv(0, 0); + } + return res; +#else + ast_fdset read_descs, write_descs, except_descs; + int ready_descriptors, max_fd = 0; + + FD_ZERO(&read_descs); + FD_ZERO(&write_descs); + FD_ZERO(&except_descs); + + if (pArray) { + max_fd = map_poll_spec(pArray, n_fds, &read_descs, &write_descs, &except_descs); + } + + ready_descriptors = ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, tv); + + if (ready_descriptors >= 0) { + map_select_results(pArray, n_fds, &read_descs, &write_descs, &except_descs); + } + + return ready_descriptors; +#endif +} + + |