s3: signals are processed twice in child.
[ira/wip.git] / lib / tevent / tevent.c
index 56fd6aec7aa54d2957f8bdcaf7e9e80a80655023..a0ee208663880d0429de3744a2b8c951e6ed183f 100644 (file)
@@ -148,6 +148,8 @@ int tevent_common_context_destructor(struct tevent_context *ev)
 
        if (ev->pipe_fde) {
                talloc_free(ev->pipe_fde);
+               close(ev->pipe_fds[0]);
+               close(ev->pipe_fds[1]);
                ev->pipe_fde = NULL;
        }
 
@@ -174,6 +176,13 @@ int tevent_common_context_destructor(struct tevent_context *ev)
                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);
        }
 
        return 0;
@@ -468,6 +477,8 @@ int _tevent_loop_once(struct tevent_context *ev, const char *location)
                        errno = ELOOP;
                        return -1;
                }
+       }
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -485,7 +496,7 @@ int _tevent_loop_once(struct tevent_context *ev, const char *location)
 
        ret = ev->ops->loop_once(ev, location);
 
-       if (ev->nesting.level > 1) {
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -525,6 +536,8 @@ int _tevent_loop_until(struct tevent_context *ev,
                        errno = ELOOP;
                        return -1;
                }
+       }
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -547,7 +560,7 @@ int _tevent_loop_until(struct tevent_context *ev,
                }
        }
 
-       if (ev->nesting.level > 1) {
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -601,9 +614,5 @@ int tevent_common_loop_wait(struct tevent_context *ev,
 */
 int _tevent_loop_wait(struct tevent_context *ev, const char *location)
 {
-       int ret;
-       ev->nesting.level++;
-       ret = ev->ops->loop_wait(ev, location);
-       ev->nesting.level--;
-       return ret;
+       return ev->ops->loop_wait(ev, location);
 }