tevent: added tevent_re_initialise()
authorAndrew Tridgell <tridge@samba.org>
Fri, 26 Mar 2010 10:13:27 +0000 (21:13 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 26 Mar 2010 10:13:27 +0000 (21:13 +1100)
This allows us to re-initialise a tevent context without destroying
the pointer. That means that if someone keeps a long term ptr to the
event context across a fork it will still work.

This also brings the memory handling in single and standard process
models much closer together, which means less bugs that we don't find
with make test.

lib/tevent/tevent.c
lib/tevent/tevent.h

index a0ee208663880d0429de3744a2b8c951e6ed183f..ceae534c9bf905393a9805e106681167c8017b99 100644 (file)
@@ -616,3 +616,18 @@ int _tevent_loop_wait(struct tevent_context *ev, const char *location)
 {
        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);
+}
index e318a4bf1d51a99665c0037cb49a8b551dd22255..ad1f2c9cc3c3cb490356e6c6fc34df8574def5db 100644 (file)
@@ -366,6 +366,8 @@ int _tevent_loop_until(struct tevent_context *ev,
        _tevent_loop_until(ev, finished, private_data, __location__)
 #endif
 
+int tevent_re_initialise(struct tevent_context *ev);
+
 
 /**
  * The following structure and registration functions are exclusively