summaryrefslogtreecommitdiff
path: root/main/timing.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-11-05 23:10:14 +0000
committerMatthew Jordan <mjordan@digium.com>2012-11-05 23:10:14 +0000
commita0c363e227aa728ea0a1ddad048683a82a373cca (patch)
tree6c89b8c6a9399b38863e8203849a4f90530bde26 /main/timing.c
parent5336a97f25c67220384b2c602d23748dd31c7c29 (diff)
Refactor ast_timer_ack to return an error and handle the error in timer users
Currently, if an acknowledgement of a timer fails Asterisk will not realize that a serious error occurred and will continue attempting to use the timer's file descriptor. This can lead to situations where errors stream to the CLI/log file. This consumes significant resources, masks the actual problem that occurred (whatever caused the timer to fail in the first place), and can leave channels in odd states. This patch propagates the errors in the timing resource modules up through the timer core, and makes users of these timers handle acknowledgement failures. It also adds some defensive coding around the use of timers to prevent using bad file descriptors in off nominal code paths. Note that the patch created by the issue reporter was modified slightly for this commit and backported to 1.8, as it was originally written for Asterisk 10. Review: https://reviewboard.asterisk.org/r/2178/ (issue ASTERISK-20032) Reported by: Jeremiah Gowdy patches: jgowdy-timerfd-6-22-2012.diff uploaded by Jeremiah Gowdy (license 6358) ........ Merged revisions 375893 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 375894 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 375895 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@375896 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/timing.c')
-rw-r--r--main/timing.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/main/timing.c b/main/timing.c
index c237d0899..f2211d484 100644
--- a/main/timing.c
+++ b/main/timing.c
@@ -150,6 +150,7 @@ struct ast_timer *ast_timer_open(void)
void ast_timer_close(struct ast_timer *handle)
{
handle->holder->iface->timer_close(handle->fd);
+ handle->fd = -1;
ast_module_unref(handle->holder->mod);
ast_free(handle);
}
@@ -168,9 +169,13 @@ int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
return res;
}
-void ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
+int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
{
- handle->holder->iface->timer_ack(handle->fd, quantity);
+ int res = -1;
+
+ res = handle->holder->iface->timer_ack(handle->fd, quantity);
+
+ return res;
}
int ast_timer_enable_continuous(const struct ast_timer *handle)
@@ -269,7 +274,11 @@ static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
if (res == 1) {
count++;
- ast_timer_ack(timer, 1);
+ if (ast_timer_ack(timer, 1) < 0) {
+ ast_cli(a->fd, "Timer failed to acknowledge.\n");
+ ast_timer_close(timer);
+ return CLI_FAILURE;
+ }
} else if (!res) {
ast_cli(a->fd, "poll() timed out! This is bad.\n");
} else if (errno != EAGAIN && errno != EINTR) {
@@ -278,6 +287,7 @@ static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
}
ast_timer_close(timer);
+ timer = NULL;
ast_cli(a->fd, "It has been %" PRIi64 " milliseconds, and we got %d timer ticks\n",
ast_tvdiff_ms(end, start), count);