diff options
author | Volker Lendecke <vl@samba.org> | 2014-02-18 20:51:23 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-02-19 16:38:30 -0800 |
commit | bd55fdbf09bd91351e097d4b71925c84de7b2a6e (patch) | |
tree | 6089193f4621f5f9c181ea31d898c956ac080af1 | |
parent | fb35d17e438772a357c442f15932986affb7c927 (diff) | |
download | samba-bd55fdbf09bd91351e097d4b71925c84de7b2a6e.tar.gz samba-bd55fdbf09bd91351e097d4b71925c84de7b2a6e.tar.xz samba-bd55fdbf09bd91351e097d4b71925c84de7b2a6e.zip |
messaging: Enforce just one messaging context
The current messaging implementation is based on a tdb indexed by server_id. If
we have more than one messaging context in a process, messages might not arrive
at the right context and be dropped, depending on which signal handler is
triggered first.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | source3/lib/messages_local.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 6b9c251cbb..4f8d81c8bf 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -53,6 +53,7 @@ struct messaging_tdb_context { struct tdb_wrap *tdb; struct tevent_signal *se; int received_messages; + bool *have_context; }; static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, @@ -77,6 +78,8 @@ static void messaging_tdb_signal_handler(struct tevent_context *ev_ctx, message_dispatch(ctx->msg_ctx); } +static int messaging_tdb_context_destructor(struct messaging_tdb_context *ctx); + /**************************************************************************** Initialise the messaging functions. ****************************************************************************/ @@ -88,6 +91,12 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, struct messaging_backend *result; struct messaging_tdb_context *ctx; struct loadparm_context *lp_ctx; + static bool have_context = false; + + if (have_context) { + DEBUG(0, ("No two messaging contexts per process\n")); + return NT_STATUS_OBJECT_NAME_COLLISION; + } if (!(result = talloc(mem_ctx, struct messaging_backend))) { DEBUG(0, ("talloc failed\n")); @@ -110,6 +119,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, result->send_fn = messaging_tdb_send; ctx->msg_ctx = msg_ctx; + ctx->have_context = &have_context; ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH, @@ -139,10 +149,20 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, sec_init(); + have_context = true; + talloc_set_destructor(ctx, messaging_tdb_context_destructor); + *presult = result; return NT_STATUS_OK; } +static int messaging_tdb_context_destructor(struct messaging_tdb_context *ctx) +{ + SMB_ASSERT(*ctx->have_context); + *ctx->have_context = false; + return 0; +} + bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx) { struct tdb_wrap *db; |