From: Stefan Metzmacher Date: Fri, 23 Mar 2018 13:48:46 +0000 (+0100) Subject: s3:messages: allow messaging_{dgm,ctdb}_register_tevent_context() to use wrapper... X-Git-Tag: tdb-1.3.16~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=660cf86639753edaa7a7a21a5b5ae207ae7d4260;p=thirdparty%2Fsamba.git s3:messages: allow messaging_{dgm,ctdb}_register_tevent_context() to use wrapper tevent_context This is only allowed if the raw tevent context is already registered. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/lib/messages_ctdb.c b/source3/lib/messages_ctdb.c index a1aeb37af19..11fe72661cc 100644 --- a/source3/lib/messages_ctdb.c +++ b/source3/lib/messages_ctdb.c @@ -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; diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 1c76615093c..0ad8f46e09f 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -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;