The branch, master has been updated
       via  402c3c4 tevent: version 0.9.31
       via  d05dfe3 messaging: Add an indirection for 
messaging_dgm_register_tevent_context
       via  34292d0 messages_dgm: Avoid an unnecessary declaration
      from  23e77c5 messaging: Avoid crashes

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 402c3c4062864df4a6da76df9ac1734c7bcbee8e
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Oct 5 08:59:19 2016 +0200

    tevent: version 0.9.31
    
    * tevent_update_timer() and tevent_req_reset_endtime() have been added
    * documentation updates
    * it is now safe to talloc_free() a tevent_threaded_context,
      all running threads keep running until they're finished,
      but we no longer abort().
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>
    
    Autobuild-User(master): Volker Lendecke <[email protected]>
    Autobuild-Date(master): Wed Oct  5 15:32:35 CEST 2016 on sn-devel-144

commit d05dfe38074f052a6de6f9145c63470608d16594
Author: Volker Lendecke <[email protected]>
Date:   Fri Sep 30 21:53:44 2016 -0700

    messaging: Add an indirection for messaging_dgm_register_tevent_context
    
    Only one tevent_fd is possible for every file descriptor.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>

commit 34292d0b4b0cc203677fb3464510670aec32798c
Author: Volker Lendecke <[email protected]>
Date:   Fri Sep 30 22:17:44 2016 -0700

    messages_dgm: Avoid an unnecessary declaration
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/tevent/ABI/tevent-0.9.30.sigs                  |   3 -
 .../ABI/{tevent-0.9.30.sigs => tevent-0.9.31.sigs} |   0
 lib/tevent/wscript                                 |   2 +-
 source3/lib/messages.c                             |   9 +-
 source3/lib/messages_dgm.c                         | 100 ++++++++++++++++++++-
 source3/lib/messages_dgm.h                         |   5 +-
 source3/lib/messages_dgm_ref.c                     |  17 ++--
 7 files changed, 113 insertions(+), 23 deletions(-)
 copy lib/tevent/ABI/{tevent-0.9.30.sigs => tevent-0.9.31.sigs} (100%)


Changeset truncated at 500 lines:

diff --git a/lib/tevent/ABI/tevent-0.9.30.sigs 
b/lib/tevent/ABI/tevent-0.9.30.sigs
index 7a6a236..9b8bfa1 100644
--- a/lib/tevent/ABI/tevent-0.9.30.sigs
+++ b/lib/tevent/ABI/tevent-0.9.30.sigs
@@ -36,7 +36,6 @@ tevent_common_loop_wait: int (struct tevent_context *, const 
char *)
 tevent_common_schedule_immediate: void (struct tevent_immediate *, struct 
tevent_context *, tevent_immediate_handler_t, void *, const char *, const char 
*)
 tevent_common_threaded_activate_immediate: void (struct tevent_context *)
 tevent_common_wakeup: int (struct tevent_context *)
-tevent_common_wakeup_fd: int (int)
 tevent_common_wakeup_init: int (struct tevent_context *)
 tevent_context_init: struct tevent_context *(TALLOC_CTX *)
 tevent_context_init_byname: struct tevent_context *(TALLOC_CTX *, const char *)
@@ -69,7 +68,6 @@ tevent_req_poll: bool (struct tevent_req *, struct 
tevent_context *)
 tevent_req_post: struct tevent_req *(struct tevent_req *, struct 
tevent_context *)
 tevent_req_print: char *(TALLOC_CTX *, struct tevent_req *)
 tevent_req_received: void (struct tevent_req *)
-tevent_req_reset_endtime: void (struct tevent_req *)
 tevent_req_set_callback: void (struct tevent_req *, tevent_req_fn, void *)
 tevent_req_set_cancel_fn: void (struct tevent_req *, tevent_req_cancel_fn)
 tevent_req_set_cleanup_fn: void (struct tevent_req *, tevent_req_cleanup_fn)
@@ -94,6 +92,5 @@ tevent_timeval_set: struct timeval (uint32_t, uint32_t)
 tevent_timeval_until: struct timeval (const struct timeval *, const struct 
timeval *)
 tevent_timeval_zero: struct timeval (void)
 tevent_trace_point_callback: void (struct tevent_context *, enum 
tevent_trace_point)
-tevent_update_timer: void (struct tevent_timer *, struct timeval)
 tevent_wakeup_recv: bool (struct tevent_req *)
 tevent_wakeup_send: struct tevent_req *(TALLOC_CTX *, struct tevent_context *, 
struct timeval)
diff --git a/lib/tevent/ABI/tevent-0.9.30.sigs 
b/lib/tevent/ABI/tevent-0.9.31.sigs
similarity index 100%
copy from lib/tevent/ABI/tevent-0.9.30.sigs
copy to lib/tevent/ABI/tevent-0.9.31.sigs
diff --git a/lib/tevent/wscript b/lib/tevent/wscript
index 380316d..580ca4d 100755
--- a/lib/tevent/wscript
+++ b/lib/tevent/wscript
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 APPNAME = 'tevent'
-VERSION = '0.9.30'
+VERSION = '0.9.31'
 
 blddir = 'bin'
 
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index fd128e9..08942a6 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -637,7 +637,7 @@ static struct messaging_rec *messaging_rec_dup(TALLOC_CTX 
*mem_ctx,
 struct messaging_filtered_read_state {
        struct tevent_context *ev;
        struct messaging_context *msg_ctx;
-       void *tevent_handle;
+       struct messaging_dgm_fde *fde;
 
        bool (*filter)(struct messaging_rec *rec, void *private_data);
        void *private_data;
@@ -674,9 +674,8 @@ struct tevent_req *messaging_filtered_read_send(
         */
        tevent_req_defer_callback(req, state->ev);
 
-       state->tevent_handle = messaging_dgm_register_tevent_context(
-               state, ev);
-       if (tevent_req_nomem(state->tevent_handle, req)) {
+       state->fde = messaging_dgm_register_tevent_context(state, ev);
+       if (tevent_req_nomem(state->fde, req)) {
                return tevent_req_post(req, ev);
        }
 
@@ -718,7 +717,7 @@ static void messaging_filtered_read_cleanup(struct 
tevent_req *req,
 
        tevent_req_set_cleanup_fn(req, NULL);
 
-       TALLOC_FREE(state->tevent_handle);
+       TALLOC_FREE(state->fde);
 
        /*
         * Just set the [new_]waiters entry to NULL, be careful not to mess
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index 7991d42..39b779b 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -41,7 +41,24 @@ struct sun_path_buf {
        char buf[sizeof(struct sockaddr_un)];
 };
 
-struct messaging_dgm_context;
+/*
+ * We can only have one tevent_fd per dgm_context and per
+ * tevent_context. Maintain a list of registered tevent_contexts per
+ * dgm_context.
+ */
+struct messaging_dgm_fde_ev {
+       struct messaging_dgm_fde_ev *prev, *next;
+
+       /*
+        * Backreference to enable DLIST_REMOVE from our
+        * destructor. Also, set to NULL when the dgm_context dies
+        * before the messaging_dgm_fde_ev.
+        */
+       struct messaging_dgm_context *ctx;
+
+       struct tevent_context *ev;
+       struct tevent_fd *fde;
+};
 
 struct messaging_dgm_out {
        struct messaging_dgm_out *prev, *next;
@@ -77,6 +94,7 @@ struct messaging_dgm_context {
        int sock;
        struct messaging_dgm_in_msg *in_msgs;
 
+       struct messaging_dgm_fde_ev *fde_evs;
        void (*recv_cb)(struct tevent_context *ev,
                        const uint8_t *msg,
                        size_t msg_len,
@@ -938,6 +956,11 @@ static int messaging_dgm_context_destructor(struct 
messaging_dgm_context *c)
        while (c->in_msgs != NULL) {
                TALLOC_FREE(c->in_msgs);
        }
+       while (c->fde_evs != NULL) {
+               tevent_fd_set_flags(c->fde_evs->fde, 0);
+               c->fde_evs->ctx = NULL;
+               DLIST_REMOVE(c->fde_evs, c->fde_evs);
+       }
 
        close(c->sock);
 
@@ -1351,14 +1374,83 @@ int messaging_dgm_wipe(void)
        return 0;
 }
 
-struct tevent_fd *messaging_dgm_register_tevent_context(
+struct messaging_dgm_fde {
+       struct tevent_fd *fde;
+};
+
+static int messaging_dgm_fde_ev_destructor(struct messaging_dgm_fde_ev *fde_ev)
+{
+       if (fde_ev->ctx != NULL) {
+               DLIST_REMOVE(fde_ev->ctx->fde_evs, fde_ev);
+               fde_ev->ctx = NULL;
+       }
+       return 0;
+}
+
+struct messaging_dgm_fde *messaging_dgm_register_tevent_context(
        TALLOC_CTX *mem_ctx, struct tevent_context *ev)
 {
        struct messaging_dgm_context *ctx = global_dgm_context;
+       struct messaging_dgm_fde_ev *fde_ev;
+       struct messaging_dgm_fde *fde;
 
        if (ctx == NULL) {
                return NULL;
        }
-       return tevent_add_fd(ev, mem_ctx, ctx->sock, TEVENT_FD_READ,
-                            messaging_dgm_read_handler, ctx);
+
+       fde = talloc(mem_ctx, struct messaging_dgm_fde);
+       if (fde == NULL) {
+               return NULL;
+       }
+
+       for (fde_ev = ctx->fde_evs; fde_ev != NULL; fde_ev = fde_ev->next) {
+               if ((fde_ev->ev == ev) &&
+                   (tevent_fd_get_flags(fde_ev->fde) != 0)) {
+                       break;
+               }
+       }
+
+       if (fde_ev == NULL) {
+               fde_ev = talloc(fde, struct messaging_dgm_fde_ev);
+               if (fde_ev == NULL) {
+                       return NULL;
+               }
+               fde_ev->fde = tevent_add_fd(
+                       ev, fde_ev, ctx->sock, TEVENT_FD_READ,
+                       messaging_dgm_read_handler, ctx);
+               if (fde_ev->fde == NULL) {
+                       TALLOC_FREE(fde);
+                       return NULL;
+               }
+               fde_ev->ev = ev;
+               fde_ev->ctx = ctx;
+               DLIST_ADD(ctx->fde_evs, fde_ev);
+               talloc_set_destructor(
+                       fde_ev, messaging_dgm_fde_ev_destructor);
+       } else {
+               /*
+                * Same trick as with tdb_wrap: The caller will never
+                * see the talloc_referenced object, the
+                * messaging_dgm_fde_ev, so problems with
+                * talloc_unlink will not happen.
+                */
+               if (talloc_reference(fde, fde_ev) == NULL) {
+                       TALLOC_FREE(fde);
+                       return NULL;
+               }
+       }
+
+       fde->fde = fde_ev->fde;
+       return fde;
+}
+
+bool messaging_dgm_fde_active(struct messaging_dgm_fde *fde)
+{
+       uint16_t flags;
+
+       if (fde == NULL) {
+               return false;
+       }
+       flags = tevent_fd_get_flags(fde->fde);
+       return (flags != 0);
 }
diff --git a/source3/lib/messages_dgm.h b/source3/lib/messages_dgm.h
index 3d450a1..ca11db1 100644
--- a/source3/lib/messages_dgm.h
+++ b/source3/lib/messages_dgm.h
@@ -42,7 +42,10 @@ int messaging_dgm_send(pid_t pid,
                       const int *fds, size_t num_fds);
 int messaging_dgm_cleanup(pid_t pid);
 int messaging_dgm_wipe(void);
-struct tevent_fd *messaging_dgm_register_tevent_context(
+
+struct messaging_dgm_fde;
+struct messaging_dgm_fde *messaging_dgm_register_tevent_context(
        TALLOC_CTX *mem_ctx, struct tevent_context *ev);
+bool messaging_dgm_fde_active(struct messaging_dgm_fde *fde);
 
 #endif
diff --git a/source3/lib/messages_dgm_ref.c b/source3/lib/messages_dgm_ref.c
index bc6b69f..39d2270 100644
--- a/source3/lib/messages_dgm_ref.c
+++ b/source3/lib/messages_dgm_ref.c
@@ -26,7 +26,7 @@
 
 struct msg_dgm_ref {
        struct msg_dgm_ref *prev, *next;
-       struct tevent_fd *tevent_handle;
+       struct messaging_dgm_fde *fde;
        void (*recv_cb)(struct tevent_context *ev,
                        const uint8_t *msg, size_t msg_len,
                        int *fds, size_t num_fds, void *private_data);
@@ -59,7 +59,7 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct 
tevent_context *ev,
                *err = ENOMEM;
                return NULL;
        }
-       result->tevent_handle = NULL;
+       result->fde = NULL;
 
        tmp_refs = refs;
 
@@ -98,9 +98,8 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct 
tevent_context *ev,
 
        }
 
-       result->tevent_handle = messaging_dgm_register_tevent_context(
-               result, ev);
-       if (result->tevent_handle == NULL) {
+       result->fde = messaging_dgm_register_tevent_context(result, ev);
+       if (result->fde == NULL) {
                TALLOC_FREE(result);
                *err = ENOMEM;
                return NULL;
@@ -129,12 +128,12 @@ static void msg_dgm_ref_recv(struct tevent_context *ev,
         * that grabs the fd's will get them.
         */
        for (r = refs; r != NULL; r = next) {
-               uint16_t flags;
+               bool active;
 
                next = r->next;
 
-               flags = tevent_fd_get_flags(r->tevent_handle);
-               if (flags == 0) {
+               active = messaging_dgm_fde_active(r->fde);
+               if (!active) {
                        /*
                         * r's tevent_context has died.
                         */
@@ -153,7 +152,7 @@ static int msg_dgm_ref_destructor(struct msg_dgm_ref *r)
        }
        DLIST_REMOVE(refs, r);
 
-       TALLOC_FREE(r->tevent_handle);
+       TALLOC_FREE(r->fde);
 
        DBG_DEBUG("refs=%p\n", refs);
 


-- 
Samba Shared Repository

Reply via email to