summaryrefslogtreecommitdiff
path: root/lib/tevent/tevent_timed.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-07-22 16:51:38 +0200
committerRalph Boehme <slow@samba.org>2018-07-11 23:04:21 +0200
commitac9569b1a61319166e497d51917db7f04a2746ce (patch)
tree51af89ac5bb309f5b977d17c94cb3b418bce56ed /lib/tevent/tevent_timed.c
parente239cbc1fd7ad3008ecb423f7dcb82651d2df420 (diff)
downloadsamba-ac9569b1a61319166e497d51917db7f04a2746ce.tar.gz
tevent: add tevent_context_wrapper_create() infrastructure
This allows to specify wrapper tevent_contexts, which adds the ability to run functions before and after the event handler functions. This can be used to implement impersonation hooks or advanced debugging/profiling hooks. We'll undo the 0.9.36 ABI change on the 0.9.37 release at the end of this patchset. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/tevent/tevent_timed.c')
-rw-r--r--lib/tevent/tevent_timed.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c
index cb948d4ba29..b521f096c48 100644
--- a/lib/tevent/tevent_timed.c
+++ b/lib/tevent/tevent_timed.c
@@ -157,6 +157,7 @@ done:
if (te->busy) {
return -1;
}
+ te->wrapper = NULL;
return 0;
}
@@ -319,6 +320,8 @@ int tevent_common_invoke_timer_handler(struct tevent_timer *te,
struct timeval current_time,
bool *removed)
{
+ struct tevent_context *handler_ev = te->event_ctx;
+
if (removed != NULL) {
*removed = false;
}
@@ -349,13 +352,40 @@ int tevent_common_invoke_timer_handler(struct tevent_timer *te,
* otherwise we pass the current time
*/
te->busy = true;
- te->handler(te->event_ctx, te, current_time, te->private_data);
+ if (te->wrapper != NULL) {
+ handler_ev = te->wrapper->wrap_ev;
+
+ tevent_wrapper_push_use_internal(handler_ev, te->wrapper);
+ te->wrapper->ops->before_timer_handler(
+ te->wrapper->wrap_ev,
+ te->wrapper->private_state,
+ te->wrapper->main_ev,
+ te,
+ te->next_event,
+ current_time,
+ te->handler_name,
+ te->location);
+ }
+ te->handler(handler_ev, te, current_time, te->private_data);
+ if (te->wrapper != NULL) {
+ te->wrapper->ops->after_timer_handler(
+ te->wrapper->wrap_ev,
+ te->wrapper->private_state,
+ te->wrapper->main_ev,
+ te,
+ te->next_event,
+ current_time,
+ te->handler_name,
+ te->location);
+ tevent_wrapper_pop_use_internal(handler_ev, te->wrapper);
+ }
te->busy = false;
tevent_debug(te->event_ctx, TEVENT_DEBUG_TRACE,
"Ending timer event %p \"%s\"\n",
te, te->handler_name);
+ te->wrapper = NULL;
te->event_ctx = NULL;
talloc_set_destructor(te, NULL);
TALLOC_FREE(te);