]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:messages: allow messaging_{dgm,ctdb}_register_tevent_context() to use wrapper...
authorStefan Metzmacher <metze@samba.org>
Fri, 23 Mar 2018 13:48:46 +0000 (14:48 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 11 Jul 2018 21:04:23 +0000 (23:04 +0200)
This is only allowed if the raw tevent context is already registered.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/messages_ctdb.c
source3/lib/messages_dgm.c

index a1aeb37af19867ef2fa9093d75322a5620aa7b65..11fe72661cc302383a34e5cfd15643c5922e7421 100644 (file)
@@ -209,14 +209,6 @@ struct messaging_ctdb_fde *messaging_ctdb_register_tevent_context(
                return NULL;
        }
 
-       if (tevent_context_is_wrapper(ev)) {
-               /*
-                * This is really a programmer error!
-                */
-               DBG_ERR("Should not be used with a wrapper tevent context\n");
-               return NULL;
-       }
-
        fde = talloc(mem_ctx, struct messaging_ctdb_fde);
        if (fde == NULL) {
                return NULL;
@@ -234,7 +226,24 @@ struct messaging_ctdb_fde *messaging_ctdb_register_tevent_context(
                         */
                        continue;
                }
-               if (fde_ev->ev == ev) {
+
+               /*
+                * We can only have one tevent_fd
+                * per low level tevent_context.
+                *
+                * This means any wrapper tevent_context
+                * needs to share the structure with
+                * the main tevent_context and/or
+                * any sibling wrapper tevent_context.
+                *
+                * This means we need to use tevent_context_same_loop()
+                * instead of just (fde_ev->ev == ev).
+                *
+                * Note: the tevent_context_is_wrapper() check below
+                * makes sure that fde_ev->ev is always a raw
+                * tevent context.
+                */
+               if (tevent_context_same_loop(fde_ev->ev, ev)) {
                        break;
                }
        }
@@ -242,6 +251,17 @@ struct messaging_ctdb_fde *messaging_ctdb_register_tevent_context(
        if (fde_ev == NULL) {
                int sock = ctdbd_conn_get_fd(ctx->conn);
 
+               if (tevent_context_is_wrapper(ev)) {
+                       /*
+                        * This is really a programmer error!
+                        *
+                        * The main/raw tevent context should
+                        * have been registered first!
+                        */
+                       DBG_ERR("Should not be used with a wrapper tevent context\n");
+                       return NULL;
+               }
+
                fde_ev = talloc(fde, struct messaging_ctdb_fde_ev);
                if (fde_ev == NULL) {
                        return NULL;
index 1c76615093c0d397e0d62fa550d3db7182b9a801..0ad8f46e09f13086ccb75776fd8419f438652934 100644 (file)
@@ -1679,14 +1679,6 @@ struct messaging_dgm_fde *messaging_dgm_register_tevent_context(
                return NULL;
        }
 
-       if (tevent_context_is_wrapper(ev)) {
-               /*
-                * This is really a programmer error!
-                */
-               DBG_ERR("Should not be used with a wrapper tevent context\n");
-               return NULL;
-       }
-
        fde = talloc(mem_ctx, struct messaging_dgm_fde);
        if (fde == NULL) {
                return NULL;
@@ -1704,12 +1696,40 @@ struct messaging_dgm_fde *messaging_dgm_register_tevent_context(
                         */
                        continue;
                }
-               if (fde_ev->ev == ev) {
+
+               /*
+                * We can only have one tevent_fd
+                * per low level tevent_context.
+                *
+                * This means any wrapper tevent_context
+                * needs to share the structure with
+                * the main tevent_context and/or
+                * any sibling wrapper tevent_context.
+                *
+                * This means we need to use tevent_context_same_loop()
+                * instead of just (fde_ev->ev == ev).
+                *
+                * Note: the tevent_context_is_wrapper() check below
+                * makes sure that fde_ev->ev is always a raw
+                * tevent context.
+                */
+               if (tevent_context_same_loop(fde_ev->ev, ev)) {
                        break;
                }
        }
 
        if (fde_ev == NULL) {
+               if (tevent_context_is_wrapper(ev)) {
+                       /*
+                        * This is really a programmer error!
+                        *
+                        * The main/raw tevent context should
+                        * have been registered first!
+                        */
+                       DBG_ERR("Should not be used with a wrapper tevent context\n");
+                       return NULL;
+               }
+
                fde_ev = talloc(fde, struct messaging_dgm_fde_ev);
                if (fde_ev == NULL) {
                        return NULL;