[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Fri Feb 13 18:00:03 MST 2015


The branch, master has been updated
       via  6f41a78 messaging4: Enable POOL_USAGE
       via  8bc5b73 lib: Use talloc_report_str
       via  35189ec lib: Add talloc_report_str()
       via  08ff9e8 messaging4: Use messages_dgm
       via  5681cca messaging3: Use message_hdr_[put|get]
       via  d80193c messaging: Define a binary format for message headers
       via  b47db91 lib: Add server_id marshalling
       via  975b9b0 ctdb: server_id_get->server_id_fetch
       via  f4cd1eb messaging3: Use messaging_dgm_ref
       via  0108c29 lib: Add messages_dgm_ref.[ch]
       via  a15a429 messages_dgm: Make it an independent lib
       via  bc986ff messages_dgm: Add a few #includes
       via  69f9ff7 unix_msg: remove cookie from unix_msg_init
       via  a3efb70 messages_dgm: Move directory handling up
       via  293a602 messages_dgm: Only pass "unique" to messaging_dgm_init
       via  5f66ddf messaging4: Use server_id_db
      from  9077fc7 Remove an unused function call.

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


- Log -----------------------------------------------------------------
commit 6f41a78c0ec9b5c0e0df18d8dd63facf0e457c05
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Feb 11 15:31:26 2015 +0000

    messaging4: Enable POOL_USAGE
    
    With this you can watch "samba"'s talloc hierarchy live using
    
    smbcontrol <pid> pool-usage
    
    Enjoy :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Sat Feb 14 01:59:19 CET 2015 on sn-devel-104

commit 8bc5b7369d2a2106ca9e0774cf9c95068968602b
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Feb 10 22:17:44 2015 +0100

    lib: Use talloc_report_str
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 35189ec68174cbf14218ca90d4bec0f6598b5f32
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Feb 11 12:19:05 2015 +0000

    lib: Add talloc_report_str()
    
    This creates a talloc report into a string and will replace the code used in
    source3/lib/tallocmsg.c
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 08ff9e80dee211dc1c25e10c7584e98f2e766f5e
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Feb 8 15:33:39 2015 +0100

    messaging4: Use messages_dgm
    
    This replaces the transport mechanism in source4 with calls to the
    messages_dgm code. It is supposed to enable "smbcontrol samba pool-usage"
    as an example without having to rewrite smbcontrol using the source4
    based messaging subsystem.
    
    This moves the source3 based names.tdb (which is unused so far) to the
    lock directory, source4 does not have a cache directory.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 5681cca42c1c5151212eb2f9a208116ceabdd8b1
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Feb 11 15:28:55 2015 +0000

    messaging3: Use message_hdr_[put|get]
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d80193ca36f9ca516fbb1ee3a55c7eece3a6c90c
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 16 14:09:35 2014 +0200

    messaging: Define a binary format for message headers
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit b47db91bafeee07b1671354dfde96b6513822521
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 16 02:11:19 2014 +0200

    lib: Add server_id marshalling
    
    Will be used soon to make source3 and source4 messaging-protocol
    compatible.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 975b9b03045eaf2654a77ecdf4a0c391999d7f67
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Oct 10 08:35:08 2014 +0200

    ctdb: server_id_get->server_id_fetch
    
    server_id_get with the next patch will be a global parsing function.
    I've decided to rename this here in ctdb, as it's only a static function
    in ctdb_client.c and apparently not intended for wider use. Please speak
    up if you don't like this :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit f4cd1eb42487efde580de74e975a9e7cc67e03ea
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 11:21:18 2014 +0200

    messaging3: Use messaging_dgm_ref
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 0108c2921d5b604da42ba70b1f38cda16fd071f7
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 11:15:12 2014 +0200

    lib: Add messages_dgm_ref.[ch]
    
    We only have one messaging_dgm context per process. But we will use this from
    two completely independent messaging subsystems which are independently
    initialized. We need to coordinate creation and destruction, do this via
    talloc.
    
    I know this looks like a step back, but when in the future we have really just
    one messaging subsystem, this can go again. My immediate goal is to make
    source3 and source4 transport-compatible, and this looks like a quick way
    towards that goal.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a15a4297cee8d12df449652c602573fb67bd3c23
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 11:11:46 2014 +0200

    messages_dgm: Make it an independent lib
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit bc986ffed219d0b65ec5c874c34709fd319f9a59
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 11:14:26 2014 +0200

    messages_dgm: Add a few #includes
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 69f9ff7d82484803d589e6570e8989b49f3dde2c
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Sep 14 17:52:07 2014 +0200

    unix_msg: remove cookie from unix_msg_init
    
    "pid" and "sock" are sufficient I guess as randomizers to distinguish messages.
    In theory, a pid could be recycled very quickly, which might mix up in-flight
    messages. But once a few messages have passed, "cookie" would be incremented as
    another indicator of a fresh message.
    
    Why? Remove messages_dgm dependency on samba-util
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a3efb70c87b489967fbf0a0b6873325a6a49bfea
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 10:58:15 2014 +0200

    messages_dgm: Move directory handling up
    
    When we want to use messages_dgm in source4, we need to find better
    places for the lock and socket directories. Source4 does not have the
    concept of a cache directory. So I chose "private dir"/sock and "lock
    dir"/msg as subdirectories.
    
    This moves directory creation from messages_dgm.c to messages.c,
    source4/lib/messaging will have its own way of doing this.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 293a602b33f07ecf75f1ea4956c012261a6f2ae5
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 4 10:40:24 2014 +0200

    messages_dgm: Only pass "unique" to messaging_dgm_init
    
    We have only one context per pid, so messaging_dgm_init can do getpid()
    itself.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 5f66ddf094f0957062f8bd2352bf9c53938dc586
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Feb 4 11:31:24 2015 +0000

    messaging4: Use server_id_db
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 ctdb/client/ctdb_client.c                          |   6 +-
 lib/util/samba_util.h                              |   3 +
 lib/util/server_id.c                               |  16 +
 lib/util/talloc_report.c                           | 174 ++++++
 lib/util/{close_low_fd.h => talloc_report.h}       |  17 +-
 lib/util/wscript_build                             |   7 +
 source3/lib/messages.c                             | 110 ++--
 source3/lib/messages_dgm.c                         | 169 +++---
 source3/lib/messages_dgm.h                         |  10 +-
 source3/lib/messages_dgm_ref.c                     | 121 ++++
 .../messages_dgm_ref.h}                            |  31 +-
 .../status_profile_dummy.c => lib/messages_util.c} |  25 +-
 .../status_profile_dummy.c => lib/messages_util.h} |  25 +-
 source3/lib/tallocmsg.c                            |  84 +--
 source3/lib/unix_msg/test_drain.c                  |   2 +-
 source3/lib/unix_msg/test_source.c                 |   2 +-
 source3/lib/unix_msg/tests.c                       |   9 +-
 source3/lib/unix_msg/unix_msg.c                    |   4 +-
 source3/lib/unix_msg/unix_msg.h                    |   3 +-
 source3/wscript_build                              |  14 +-
 source4/lib/messaging/messaging.c                  | 610 +++++----------------
 source4/lib/messaging/messaging.h                  |   4 +-
 source4/lib/messaging/wscript_build                |   2 +-
 source4/smbd/server.c                              |   2 +
 24 files changed, 699 insertions(+), 751 deletions(-)
 create mode 100644 lib/util/talloc_report.c
 copy lib/util/{close_low_fd.h => talloc_report.h} (75%)
 create mode 100644 source3/lib/messages_dgm_ref.c
 copy source3/{utils/status_profile_dummy.c => lib/messages_dgm_ref.h} (60%)
 copy source3/{utils/status_profile_dummy.c => lib/messages_util.c} (57%)
 copy source3/{utils/status_profile_dummy.c => lib/messages_util.h} (67%)


Changeset truncated at 500 lines:

diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c
index da18826..533f36f 100644
--- a/ctdb/client/ctdb_client.c
+++ b/ctdb/client/ctdb_client.c
@@ -3807,7 +3807,7 @@ struct server_id {
 	uint64_t unique_id;
 };
 
-static struct server_id server_id_get(struct ctdb_context *ctdb, uint32_t reqid)
+static struct server_id server_id_fetch(struct ctdb_context *ctdb, uint32_t reqid)
 {
 	struct server_id id;
 
@@ -3957,7 +3957,7 @@ again:
 
 	talloc_free(data.dptr);
 
-	id = server_id_get(ctdb_db->ctdb, reqid);
+	id = server_id_fetch(ctdb_db->ctdb, reqid);
 
 	i = 0;
 	while (i < locks->num) {
@@ -4046,7 +4046,7 @@ static bool g_lock_unlock(TALLOC_CTX *mem_ctx,
 
 	talloc_free(data.dptr);
 
-	id = server_id_get(ctdb_db->ctdb, reqid);
+	id = server_id_fetch(ctdb_db->ctdb, reqid);
 
 	for (i=0; i<locks->num; i++) {
 		if (ctdb_server_id_equal(&locks->lock[i].id, &id)) {
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 1c7ae79..7adcdba 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -899,6 +899,9 @@ void server_id_set_disconnected(struct server_id *id);
  */
 bool server_id_is_disconnected(const struct server_id *id);
 
+void server_id_put(uint8_t buf[24], const struct server_id id);
+void server_id_get(struct server_id *id, const uint8_t buf[24]);
+
 /*
  * Samba code should use samba_tevent_context_init() instead of
  * tevent_context_init() in order to get the debug output.
diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 7d3de2f..308ee2a 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -150,3 +150,19 @@ bool server_id_is_disconnected(const struct server_id *id)
 
 	return server_id_equal(id, &dis);
 }
+
+void server_id_put(uint8_t buf[24], const struct server_id id)
+{
+	SBVAL(buf, 0,  id.pid);
+	SIVAL(buf, 8,  id.task_id);
+	SIVAL(buf, 12, id.vnn);
+	SBVAL(buf, 16, id.unique_id);
+}
+
+void server_id_get(struct server_id *id, const uint8_t buf[24])
+{
+	id->pid       = BVAL(buf, 0);
+	id->task_id   = IVAL(buf, 8);
+	id->vnn       = IVAL(buf, 12);
+	id->unique_id = BVAL(buf, 16);
+}
diff --git a/lib/util/talloc_report.c b/lib/util/talloc_report.c
new file mode 100644
index 0000000..8d7d548
--- /dev/null
+++ b/lib/util/talloc_report.c
@@ -0,0 +1,174 @@
+/*
+ * talloc_report into a string
+ *
+ * Copyright Volker Lendecke <vl at samba.org> 2015
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "talloc_report.h"
+
+/*
+ * talloc_vasprintf into a buffer that doubles its size. The real string
+ * length is maintained in "pstr_len".
+ */
+
+static char *talloc_vasprintf_append_largebuf(char *buf, ssize_t *pstr_len,
+					      const char *fmt, va_list ap)
+{
+	ssize_t str_len = *pstr_len;
+	size_t buflen, needed, space;
+	char *start, *tmpbuf;
+	va_list ap2;
+	int printlen;
+
+	if (str_len == -1) {
+		return NULL;
+	}
+	if (buf == NULL) {
+		return NULL;
+	}
+	buflen = talloc_get_size(buf);
+
+	if (buflen > str_len) {
+		start = buf + str_len;
+		space = buflen - str_len;
+	} else {
+		start = NULL;
+		space = 0;
+	}
+
+	va_copy(ap2, ap);
+	printlen = vsnprintf(start, space, fmt, ap2);
+	va_end(ap2);
+
+	if (printlen < 0) {
+		goto fail;
+	}
+
+	needed = str_len + printlen + 1;
+
+	if (needed > buflen) {
+		buflen = MAX(128, buflen);
+
+		while (buflen < needed) {
+			buflen *= 2;
+		}
+
+		tmpbuf = talloc_realloc(NULL, buf, char, buflen);
+		if (tmpbuf == NULL) {
+			goto fail;
+		}
+		buf = tmpbuf;
+
+		va_copy(ap2, ap);
+		vsnprintf(buf + str_len, buflen - str_len, fmt, ap2);
+		va_end(ap2);
+	}
+	*pstr_len = (needed - 1);
+	return buf;
+fail:
+	*pstr_len = -1;
+	return buf;
+}
+
+static char *talloc_asprintf_append_largebuf(char *buf, ssize_t *pstr_len,
+					     const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	buf = talloc_vasprintf_append_largebuf(buf, pstr_len, fmt, ap);
+	va_end(ap);
+	return buf;
+}
+
+struct talloc_report_str_state {
+	ssize_t str_len;
+	char *s;
+};
+
+static void talloc_report_str_helper(const void *ptr, int depth, int max_depth,
+				     int is_ref, void *private_data)
+{
+	struct talloc_report_str_state *state = private_data;
+	const char *name = talloc_get_name(ptr);
+
+	if (ptr == state->s) {
+		return;
+	}
+
+	if (is_ref) {
+		state->s = talloc_asprintf_append_largebuf(
+			state->s, &state->str_len,
+			"%*sreference to: %s\n", depth*4, "", name);
+		return;
+	}
+
+	if (depth == 0) {
+		state->s = talloc_asprintf_append_largebuf(
+			state->s, &state->str_len,
+			"%stalloc report on '%s' "
+			"(total %6lu bytes in %3lu blocks)\n",
+			(max_depth < 0 ? "full " :""), name,
+			(unsigned long)talloc_total_size(ptr),
+			(unsigned long)talloc_total_blocks(ptr));
+		return;
+	}
+
+	if (strcmp(name, "char") == 0) {
+		/*
+		 * Print out the first 50 bytes of the string
+		 */
+		state->s = talloc_asprintf_append_largebuf(
+			state->s, &state->str_len,
+			"%*s%-30s contains %6lu bytes in %3lu blocks "
+			"(ref %d): %*s\n", depth*4, "",	name,
+			(unsigned long)talloc_total_size(ptr),
+			(unsigned long)talloc_total_blocks(ptr),
+			talloc_reference_count(ptr),
+			MIN(50, talloc_get_size(ptr)),
+			(const char *)ptr);
+		return;
+	}
+
+	state->s = talloc_asprintf_append_largebuf(
+		state->s, &state->str_len,
+		"%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n",
+		depth*4, "", name,
+		(unsigned long)talloc_total_size(ptr),
+		(unsigned long)talloc_total_blocks(ptr),
+		talloc_reference_count(ptr));
+}
+
+char *talloc_report_str(TALLOC_CTX *mem_ctx, TALLOC_CTX *root)
+{
+	struct talloc_report_str_state state;
+
+	state.s = talloc_strdup(mem_ctx, "");
+	if (state.s == NULL) {
+		return NULL;
+	}
+	state.str_len = 0;
+
+	talloc_report_depth_cb(root, 0, -1, talloc_report_str_helper, &state);
+
+	if (state.str_len == -1) {
+		talloc_free(state.s);
+		return NULL;
+	}
+
+	return talloc_realloc(mem_ctx, state.s, char, state.str_len+1);
+}
diff --git a/lib/util/close_low_fd.h b/lib/util/talloc_report.h
similarity index 75%
copy from lib/util/close_low_fd.h
copy to lib/util/talloc_report.h
index 954d1d2..53d0385 100644
--- a/lib/util/close_low_fd.h
+++ b/lib/util/talloc_report.h
@@ -1,7 +1,7 @@
 /*
- * Unix SMB/CIFS implementation.
- * Samba utility functions
- * Copyright (C) Volker Lendecke 2014
+ * talloc_report into a string
+ *
+ * Copyright Volker Lendecke <vl at samba.org> 2015
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,12 +17,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _CLOSE_LOW_FD_H
-#define _CLOSE_LOW_FD_H
+#ifndef _TALLOC_REPORT_H_
+#define _TALLOC_REPORT_H_
 
-/*
- * Redirect "fd" to /dev/null
- */
-int close_low_fd(int fd);
+#include <talloc.h>
+
+char *talloc_report_str(TALLOC_CTX *mem_ctx, TALLOC_CTX *root);
 
 #endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index c0d07e7..a1dec2a 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -95,6 +95,13 @@ if not bld.env.SAMBA_UTIL_CORE_ONLY:
                       private_library=True
                       )
 
+    bld.SAMBA_LIBRARY('talloc_report',
+                      source='talloc_report.c',
+                      local_include=False,
+                      public_deps='talloc',
+                      private_library=True
+                      )
+
     if not bld.env.disable_ntdb:
         bld.SAMBA_LIBRARY('util_ntdb',
                           source='util_ntdb.c',
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 0e53583..7df7cdb 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -54,6 +54,8 @@
 #include "lib/messages_dgm.h"
 #include "lib/iov_buf.h"
 #include "lib/util/server_id_db.h"
+#include "lib/messages_dgm_ref.h"
+#include "lib/messages_util.h"
 
 struct messaging_callback {
 	struct messaging_callback *prev, *next;
@@ -75,17 +77,12 @@ struct messaging_context {
 	struct tevent_req **waiters;
 	unsigned num_waiters;
 
+	void *msg_dgm_ref;
 	struct messaging_backend *remote;
 
 	struct server_id_db *names_db;
 };
 
-struct messaging_hdr {
-	uint32_t msg_type;
-	struct server_id dst;
-	struct server_id src;
-};
-
 /****************************************************************************
  A useful function for testing the message system.
 ****************************************************************************/
@@ -213,13 +210,13 @@ static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
 {
 	struct messaging_context *msg_ctx = talloc_get_type_abort(
 		private_data, struct messaging_context);
-	const struct messaging_hdr *hdr;
+	uint8_t hdr[MESSAGE_HDR_LENGTH];
 	struct server_id_buf idbuf;
 	struct messaging_rec rec;
 	int64_t fds64[MIN(num_fds, INT8_MAX)];
 	size_t i;
 
-	if (msg_len < sizeof(*hdr)) {
+	if (msg_len < sizeof(hdr)) {
 		for (i=0; i < num_fds; i++) {
 			close(fds[i]);
 		}
@@ -244,28 +241,22 @@ static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
 		fds[i] = -1;
 	}
 
-	/*
-	 * messages_dgm guarantees alignment, so we can cast here
-	 */
-	hdr = (const struct messaging_hdr *)msg;
-
-	DEBUG(10, ("%s: Received message 0x%x len %u (num_fds:%u) from %s\n",
-		   __func__, (unsigned)hdr->msg_type,
-		   (unsigned)(msg_len - sizeof(*hdr)),
-		   (unsigned)num_fds,
-		   server_id_str_buf(hdr->src, &idbuf)));
-
 	rec = (struct messaging_rec) {
 		.msg_version = MESSAGE_VERSION,
-		.msg_type = hdr->msg_type,
-		.src = hdr->src,
-		.dest = hdr->dst,
-		.buf.data = discard_const_p(uint8, msg) + sizeof(*hdr),
-		.buf.length = msg_len - sizeof(*hdr),
+		.buf.data = discard_const_p(uint8, msg) + sizeof(hdr),
+		.buf.length = msg_len - sizeof(hdr),
 		.num_fds = num_fds,
 		.fds = fds64,
 	};
 
+	message_hdr_get(&rec.msg_type, &rec.src, &rec.dest, msg);
+
+	DEBUG(10, ("%s: Received message 0x%x len %u (num_fds:%u) from %s\n",
+		   __func__, (unsigned)rec.msg_type,
+		   (unsigned)rec.buf.length,
+		   (unsigned)num_fds,
+		   server_id_str_buf(rec.src, &idbuf)));
+
 	messaging_dispatch_rec(msg_ctx, &rec);
 }
 
@@ -291,12 +282,20 @@ static int messaging_context_destructor(struct messaging_context *ctx)
 	return 0;
 }
 
+static const char *private_path(const char *name)
+{
+	return talloc_asprintf(talloc_tos(), "%s/%s", lp_private_dir(), name);
+}
+
 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
 					 struct tevent_context *ev)
 {
 	struct messaging_context *ctx;
 	NTSTATUS status;
 	int ret;
+	const char *lck_path;
+	const char *priv_path;
+	bool ok;
 
 	if (!(ctx = talloc_zero(mem_ctx, struct messaging_context))) {
 		return NULL;
@@ -307,18 +306,44 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
 
 	sec_init();
 
-	ret = messaging_dgm_init(ctx->event_ctx, ctx->id,
-				 lp_cache_directory(), sec_initial_uid(),
-				 messaging_recv_cb, ctx);
+	lck_path = lock_path("msg");
+	if (lck_path == NULL) {
+		TALLOC_FREE(ctx);
+		return NULL;
+	}
 
-	if (ret != 0) {
-		DEBUG(2, ("messaging_dgm_init failed: %s\n", strerror(ret)));
+	ok = directory_create_or_exist_strict(lck_path, sec_initial_uid(),
+					      0755);
+	if (!ok) {
+		DEBUG(10, ("%s: Could not create lock directory: %s\n",
+			   __func__, strerror(errno)));
+		TALLOC_FREE(ctx);
+		return NULL;
+	}
+
+	priv_path = private_path("sock");
+
+	ok = directory_create_or_exist_strict(priv_path, sec_initial_uid(),
+					      0700);
+	if (!ok) {
+		DEBUG(10, ("%s: Could not create msg directory: %s\n",
+			   __func__, strerror(errno)));
+		TALLOC_FREE(ctx);
+		return NULL;
+	}
+
+	ctx->msg_dgm_ref = messaging_dgm_ref(
+		ctx, ctx->event_ctx, ctx->id.unique_id,
+		priv_path, lck_path, messaging_recv_cb, ctx, &ret);
+
+	if (ctx->msg_dgm_ref == NULL) {
+		DEBUG(2, ("messaging_dgm_ref failed: %s\n", strerror(ret)));
 		TALLOC_FREE(ctx);
 		return NULL;
 	}
 
 	ctx->names_db = server_id_db_init(
-		ctx, ctx->id, lp_cache_directory(), 0,
+		ctx, ctx->id, lp_lock_directory(), 0,
 		TDB_INCOMPATIBLE_HASH|TDB_CLEAR_IF_FIRST);
 	if (ctx->names_db == NULL) {
 		DEBUG(10, ("%s: server_id_db_init failed\n", __func__));
@@ -364,15 +389,17 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
 	NTSTATUS status;
 	int ret;
 
-	messaging_dgm_destroy();
+	TALLOC_FREE(msg_ctx->msg_dgm_ref);
 
 	msg_ctx->id = procid_self();
 
-	ret = messaging_dgm_init(msg_ctx->event_ctx, msg_ctx->id,
-				 lp_cache_directory(), sec_initial_uid(),
-				 messaging_recv_cb, msg_ctx);
-	if (ret != 0) {
-		DEBUG(0, ("messaging_dgm_init failed: %s\n", strerror(errno)));
+	msg_ctx->msg_dgm_ref = messaging_dgm_ref(
+		msg_ctx, msg_ctx->event_ctx, msg_ctx->id.unique_id,
+		private_path("sock"), lock_path("msg"),
+		messaging_recv_cb, msg_ctx, &ret);
+
+	if (msg_ctx->msg_dgm_ref == NULL) {
+		DEBUG(2, ("messaging_dgm_ref failed: %s\n", strerror(ret)));
 		return map_nt_error_from_unix(ret);
 	}
 
@@ -496,7 +523,7 @@ NTSTATUS messaging_send_iov_from(struct messaging_context *msg_ctx,
 				 const int *fds, size_t num_fds)
 {
 	int ret;
-	struct messaging_hdr hdr;
+	uint8_t hdr[MESSAGE_HDR_LENGTH];
 	struct iovec iov2[iovlen+1];
 
 	if (server_id_is_disconnected(&dst)) {
@@ -522,13 +549,8 @@ NTSTATUS messaging_send_iov_from(struct messaging_context *msg_ctx,
 		return NT_STATUS_OK;
 	}
 
-	ZERO_STRUCT(hdr);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list