tevent: add tevent_loop_set_nesting_hook()
authorStefan Metzmacher <metze@samba.org>
Thu, 12 Mar 2009 09:23:30 +0000 (10:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Mar 2009 13:21:26 +0000 (14:21 +0100)
This is an ugly hack to let the s4 server work arround
some bugs related to nested events and uid changing.

metze

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

index a6bac6097d72f148f1442e552be890e87a61afd8..e9b6b7d055899d8f767dfcb18f803a463a74fbdd 100644 (file)
@@ -374,6 +374,14 @@ void tevent_loop_allow_nesting(struct tevent_context *ev)
        ev->nesting.allowed = true;
 }
 
+void tevent_loop_set_nesting_hook(struct tevent_context *ev,
+                                 tevent_nesting_hook hook,
+                                 void *private_data)
+{
+       ev->nesting.hook_fn = hook;
+       ev->nesting.hook_private = private_data;
+}
+
 static void tevent_abort_nesting(struct tevent_context *ev, const char *location)
 {
        const char *reason;
@@ -393,6 +401,7 @@ static void tevent_abort_nesting(struct tevent_context *ev, const char *location
 int _tevent_loop_once(struct tevent_context *ev, const char *location)
 {
        int ret;
+       void *nesting_stack_ptr = NULL;
 
        ev->nesting.level++;
 
@@ -402,12 +411,41 @@ int _tevent_loop_once(struct tevent_context *ev, const char *location)
                        errno = ELOOP;
                        return -1;
                }
+               if (ev->nesting.hook_fn) {
+                       int ret2;
+                       ret2 = ev->nesting.hook_fn(ev,
+                                                  ev->nesting.hook_private,
+                                                  ev->nesting.level,
+                                                  true,
+                                                  (void *)&nesting_stack_ptr,
+                                                  location);
+                       if (ret2 != 0) {
+                               ret = ret2;
+                               goto done;
+                       }
+               }
        }
 
        ret = ev->ops->loop_once(ev, location);
 
-       ev->nesting.level--;
+       if (ev->nesting.level > 1) {
+               if (ev->nesting.hook_fn) {
+                       int ret2;
+                       ret2 = ev->nesting.hook_fn(ev,
+                                                  ev->nesting.hook_private,
+                                                  ev->nesting.level,
+                                                  false,
+                                                  (void *)&nesting_stack_ptr,
+                                                  location);
+                       if (ret2 != 0) {
+                               ret = ret2;
+                               goto done;
+                       }
+               }
+       }
 
+done:
+       ev->nesting.level--;
        return ret;
 }
 
index 67946279476d75babc241364716a1d675bcd7209..bb36f39739587e03d58a5ec00c75fbe741eb5d62 100644 (file)
@@ -301,6 +301,12 @@ void tevent_queue_stop(struct tevent_queue *queue);
 
 size_t tevent_queue_length(struct tevent_queue *queue);
 
+typedef int (*tevent_nesting_hook)(struct tevent_context *ev,
+                                  void *private_data,
+                                  uint32_t level,
+                                  bool begin,
+                                  void *stack_ptr,
+                                  const char *location);
 #ifdef TEVENT_DEPRECATED
 #ifndef _DEPRECATED_
 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
@@ -310,6 +316,9 @@ size_t tevent_queue_length(struct tevent_queue *queue);
 #endif
 #endif
 void tevent_loop_allow_nesting(struct tevent_context *ev) _DEPRECATED_;
+void tevent_loop_set_nesting_hook(struct tevent_context *ev,
+                                 tevent_nesting_hook hook,
+                                 void *private_data) _DEPRECATED_;
 #endif
 
 #ifdef TEVENT_COMPAT_DEFINES
index 475d00661a0c82f4d04df0579a98333e5827b514..f10485398f147315d6c71e3058734795f4fb38f7 100644 (file)
@@ -238,6 +238,8 @@ struct tevent_context {
        struct {
                bool allowed;
                uint32_t level;
+               tevent_nesting_hook hook_fn;
+               void *hook_private;
        } nesting;
 };