}
}
- e = talloc(talloc_autofree_context(), struct tevent_ops_list);
+ e = talloc(NULL, struct tevent_ops_list);
if (e == NULL) return false;
e->name = name;
void tevent_set_default_backend(const char *backend)
{
talloc_free(tevent_default_backend);
- tevent_default_backend = talloc_strdup(talloc_autofree_context(),
- backend);
+ tevent_default_backend = talloc_strdup(NULL, backend);
}
/*
*/
static void tevent_backend_init(void)
{
+ static bool done;
+
+ if (done) {
+ return;
+ }
+
+ done = true;
+
tevent_select_init();
- tevent_standard_init();
+ tevent_poll_init();
+ tevent_poll_mt_init();
#ifdef HAVE_EPOLL
tevent_epoll_init();
#endif
+#ifdef HAVE_KQUEUE
+ tevent_kqueue_init();
+#endif
+ tevent_standard_init();
+}
+
+_PRIVATE_ const struct tevent_ops *tevent_find_ops_byname(const char *name)
+{
+ struct tevent_ops_list *e;
+
+ tevent_backend_init();
+
+ if (name == NULL) {
+ name = tevent_default_backend;
+ }
+ if (name == NULL) {
+ name = "standard";
+ }
+
+ for (e = tevent_backends; e != NULL; e = e->next) {
+ if (0 == strcmp(e->name, name)) {
+ return e->ops;
+ }
+ }
+
+ return NULL;
}
/*
if (ev->pipe_fde) {
talloc_free(ev->pipe_fde);
+ close(ev->pipe_fds[0]);
+ close(ev->pipe_fds[1]);
ev->pipe_fde = NULL;
}
DLIST_REMOVE(ev->fd_events, fd);
}
+ ev->last_zero_timer = NULL;
for (te = ev->timer_events; te; te = tn) {
tn = te->next;
te->event_ctx = NULL;
sn = se->next;
se->event_ctx = NULL;
DLIST_REMOVE(ev->signal_events, se);
+ /*
+ * This is important, Otherwise signals
+ * are handled twice in child. eg, SIGHUP.
+ * one added in parent, and another one in
+ * the child. -- BoYang
+ */
+ tevent_cleanup_pending_signal_handlers(se);
}
+ /* removing nesting hook or we get an abort when nesting is
+ * not allowed. -- SSS
+ * Note that we need to leave the allowed flag at its current
+ * value, otherwise the use in tevent_re_initialise() will
+ * leave the event context with allowed forced to false, which
+ * will break users that expect nesting to be allowed
+ */
+ ev->nesting.level = 0;
+ ev->nesting.hook_fn = NULL;
+ ev->nesting.hook_private = NULL;
+
return 0;
}
NOTE: use tevent_context_init() inside of samba!
*/
-static struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
- const struct tevent_ops *ops)
+struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
+ const struct tevent_ops *ops,
+ void *additional_data)
{
struct tevent_context *ev;
int ret;
talloc_set_destructor(ev, tevent_common_context_destructor);
ev->ops = ops;
+ ev->additional_data = additional_data;
ret = ev->ops->context_init(ev);
if (ret != 0) {
struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx,
const char *name)
{
- struct tevent_ops_list *e;
-
- tevent_backend_init();
+ const struct tevent_ops *ops;
- if (name == NULL) {
- name = tevent_default_backend;
- }
- if (name == NULL) {
- name = "standard";
+ ops = tevent_find_ops_byname(name);
+ if (ops == NULL) {
+ return NULL;
}
- for (e=tevent_backends;e;e=e->next) {
- if (strcmp(name, e->name) == 0) {
- return tevent_context_init_ops(mem_ctx, e->ops);
- }
- }
- return NULL;
+ return tevent_context_init_ops(mem_ctx, ops, NULL);
}
/*
add a fd based event
return NULL on failure (memory allocation error)
-
- if flags contains TEVENT_FD_AUTOCLOSE then the fd will be closed when
- the returned fd_event context is freed
*/
struct tevent_fd *_tevent_add_fd(struct tevent_context *ev,
TALLOC_CTX *mem_ctx,
/*
schedule an immediate event
- return NULL on failure
*/
void _tevent_schedule_immediate(struct tevent_immediate *im,
struct tevent_context *ev,
}
}
+ tevent_trace_point_callback(ev, TEVENT_TRACE_BEFORE_LOOP_ONCE);
ret = ev->ops->loop_once(ev, location);
+ tevent_trace_point_callback(ev, TEVENT_TRACE_AFTER_LOOP_ONCE);
if (ev->nesting.level > 0) {
if (ev->nesting.hook_fn) {
}
while (!finished(private_data)) {
+ tevent_trace_point_callback(ev, TEVENT_TRACE_BEFORE_LOOP_ONCE);
ret = ev->ops->loop_once(ev, location);
+ tevent_trace_point_callback(ev, TEVENT_TRACE_AFTER_LOOP_ONCE);
if (ret != 0) {
break;
}
{
return ev->ops->loop_wait(ev, location);
}
+
+
+/*
+ re-initialise a tevent context. This leaves you with the same
+ event context, but all events are wiped and the structure is
+ re-initialised. This is most useful after a fork()
+
+ zero is returned on success, non-zero on failure
+*/
+int tevent_re_initialise(struct tevent_context *ev)
+{
+ tevent_common_context_destructor(ev);
+
+ return ev->ops->context_init(ev);
+}