summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-02-18 20:51:23 +0100
committerJeremy Allison <jra@samba.org>2014-05-31 01:59:18 +0200
commitc81f1aab93f613db5a7f8131e3761b0fb1c8ea83 (patch)
tree0cecdcaa33f244001d6238b0329f3eed6f94a5d3
parentc487937b0146c19d4969208519f2c11b64666842 (diff)
downloadsamba-c81f1aab93f613db5a7f8131e3761b0fb1c8ea83.tar.gz
samba-c81f1aab93f613db5a7f8131e3761b0fb1c8ea83.tar.xz
samba-c81f1aab93f613db5a7f8131e3761b0fb1c8ea83.zip
messaging3: 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. This is the same patch as bd55fdb lifted to messaging.c Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/lib/messages.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 364bbbcea4..1263bf1698 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -74,8 +74,12 @@ struct messaging_context {
struct messaging_backend *local;
struct messaging_backend *remote;
+
+ bool *have_context;
};
+static int messaging_context_destructor(struct messaging_context *msg_ctx);
+
/****************************************************************************
A useful function for testing the message system.
****************************************************************************/
@@ -205,6 +209,13 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
{
struct messaging_context *ctx;
NTSTATUS status;
+ static bool have_context = false;
+
+ if (have_context) {
+ DEBUG(0, ("No two messaging contexts per process\n"));
+ return NULL;
+ }
+
if (!(ctx = talloc_zero(mem_ctx, struct messaging_context))) {
return NULL;
@@ -212,6 +223,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
ctx->id = procid_self();
ctx->event_ctx = ev;
+ ctx->have_context = &have_context;
status = messaging_dgm_init(ctx, ctx, &ctx->local);
@@ -242,9 +254,19 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
register_dmalloc_msgs(ctx);
debug_register_msgs(ctx);
+ have_context = true;
+ talloc_set_destructor(ctx, messaging_context_destructor);
+
return ctx;
}
+static int messaging_context_destructor(struct messaging_context *msg_ctx)
+{
+ SMB_ASSERT(*msg_ctx->have_context);
+ *msg_ctx->have_context = false;
+ return 0;
+}
+
struct server_id messaging_server_id(const struct messaging_context *msg_ctx)
{
return msg_ctx->id;