Copyright (C) Andrew Tridgell 2000
Copyright (C) 2001 by Martin Pool
Copyright (C) 2002 by Jeremy Allison
+ Copyright (C) 2007 by Volker Lendecke
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 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*/
#include "includes.h"
-
-/* the locking database handle */
-static TDB_CONTEXT *tdb;
-static int received_signal;
-
-/* change the message version with any incompatible changes in the protocol */
-#define MESSAGE_VERSION 1
-
-struct message_rec {
- int msg_version;
- int msg_type;
- pid_t dest;
- pid_t src;
- size_t len;
+#include "librpc/gen_ndr/messaging.h"
+#include "librpc/gen_ndr/ndr_messaging.h"
+#include "dbwrap.h"
+#include "serverid.h"
+#include "messages.h"
+
+struct messaging_callback {
+ struct messaging_callback *prev, *next;
+ uint32 msg_type;
+ void (*fn)(struct messaging_context *msg, void *private_data,
+ uint32_t msg_type,
+ struct server_id server_id, DATA_BLOB *data);
+ void *private_data;
};
-/* we have a linked list of dispatch handlers */
-static struct dispatch_fns {
- struct dispatch_fns *next, *prev;
- int msg_type;
- void (*fn)(int msg_type, pid_t pid, void *buf, size_t len);
-} *dispatch_fns;
-
/****************************************************************************
- Notifications come in as signals.
+ A useful function for testing the message system.
****************************************************************************/
-static void sig_usr1(void)
+static void ping_message(struct messaging_context *msg_ctx,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id src,
+ DATA_BLOB *data)
{
- received_signal = 1;
- sys_select_signal();
+ const char *msg = data->data ? (const char *)data->data : "none";
+
+ DEBUG(1,("INFO: Received PING message from PID %s [%s]\n",
+ procid_str_static(&src), msg));
+ messaging_send(msg_ctx, src, MSG_PONG, data);
}
/****************************************************************************
- A useful function for testing the message system.
+ Register/replace a dispatch function for a particular message type.
+ JRA changed Dec 13 2006. Only one message handler now permitted per type.
+ *NOTE*: Dispatch functions must be able to cope with incoming
+ messages on an *odd* byte boundary.
****************************************************************************/
-static void ping_message(int msg_type, pid_t src, void *buf, size_t len)
-{
- const char *msg = buf ? buf : "none";
- DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg));
- message_send_pid(src, MSG_PONG, buf, len, True);
-}
+struct msg_all {
+ struct messaging_context *msg_ctx;
+ int msg_type;
+ uint32 msg_flag;
+ const void *buf;
+ size_t len;
+ int n_sent;
+};
/****************************************************************************
- Initialise the messaging functions.
+ Send one of the messages for the broadcast.
****************************************************************************/
-BOOL message_init(void)
+static int traverse_fn(struct db_record *rec, const struct server_id *id,
+ uint32_t msg_flags, void *state)
{
- if (tdb) return True;
+ struct msg_all *msg_all = (struct msg_all *)state;
+ NTSTATUS status;
- tdb = tdb_open_log(lock_path("messages.tdb"),
- 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
- O_RDWR|O_CREAT,0600);
+ /* Don't send if the receiver hasn't registered an interest. */
- if (!tdb) {
- DEBUG(0,("ERROR: Failed to initialise messages database\n"));
- return False;
+ if((msg_flags & msg_all->msg_flag) == 0) {
+ return 0;
}
- CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);
+ /* If the msg send fails because the pid was not found (i.e. smbd died),
+ * the msg has already been deleted from the messages.tdb.*/
- message_register(MSG_PING, ping_message);
+ status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
+ (uint8 *)msg_all->buf, msg_all->len);
- return True;
-}
+ if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
+
+ /* If the pid was not found delete the entry from connections.tdb */
-/*******************************************************************
- Form a static tdb key from a pid.
-******************************************************************/
+ DEBUG(2, ("pid %s doesn't exist\n", procid_str_static(id)));
-static TDB_DATA message_key_pid(pid_t pid)
-{
- static char key[20];
- TDB_DATA kbuf;
-
- slprintf(key, sizeof(key)-1, "PID/%d", (int)pid);
-
- kbuf.dptr = (char *)key;
- kbuf.dsize = strlen(key)+1;
- return kbuf;
+ rec->delete_rec(rec);
+ }
+ msg_all->n_sent++;
+ return 0;
}
-/****************************************************************************
- Notify a process that it has a message. If the process doesn't exist
- then delete its record in the database.
-****************************************************************************/
-
-static BOOL message_notify(pid_t pid)
+/**
+ * Send a message to all smbd processes.
+ *
+ * It isn't very efficient, but should be OK for the sorts of
+ * applications that use it. When we need efficient broadcast we can add
+ * it.
+ *
+ * @param n_sent Set to the number of messages sent. This should be
+ * equal to the number of processes, but be careful for races.
+ *
+ * @retval True for success.
+ **/
+bool message_send_all(struct messaging_context *msg_ctx,
+ int msg_type,
+ const void *buf, size_t len,
+ int *n_sent)
{
- /*
- * Doing kill with a non-positive pid causes messages to be
- * sent to places we don't want.
- */
-
- SMB_ASSERT(pid > 0);
+ struct msg_all msg_all;
- if (kill(pid, SIGUSR1) == -1) {
- if (errno == ESRCH) {
- DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
- tdb_delete(tdb, message_key_pid(pid));
- } else {
- DEBUG(2,("message to process %d failed - %s\n", (int)pid, strerror(errno)));
- }
+ msg_all.msg_type = msg_type;
+ if (msg_type < 1000)
+ msg_all.msg_flag = FLAG_MSG_GENERAL;
+ else if (msg_type > 1000 && msg_type < 2000)
+ msg_all.msg_flag = FLAG_MSG_NMBD;
+ else if (msg_type > 2000 && msg_type < 2100)
+ msg_all.msg_flag = FLAG_MSG_PRINT_NOTIFY;
+ else if (msg_type > 2100 && msg_type < 3000)
+ msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
+ else if (msg_type > 3000 && msg_type < 4000)
+ msg_all.msg_flag = FLAG_MSG_SMBD;
+ else if (msg_type > 4000 && msg_type < 5000)
+ msg_all.msg_flag = FLAG_MSG_DBWRAP;
+ else
return False;
- }
+
+ msg_all.buf = buf;
+ msg_all.len = len;
+ msg_all.n_sent = 0;
+ msg_all.msg_ctx = msg_ctx;
+
+ serverid_traverse(traverse_fn, &msg_all);
+ if (n_sent)
+ *n_sent = msg_all.n_sent;
return True;
}
-/****************************************************************************
- Send a message to a particular pid.
-****************************************************************************/
-
-static BOOL message_send_pid_internal(pid_t pid, int msg_type, const void *buf, size_t len,
- BOOL duplicates_allowed, unsigned int timeout)
+struct event_context *messaging_event_context(struct messaging_context *msg_ctx)
{
- TDB_DATA kbuf;
- TDB_DATA dbuf;
- TDB_DATA old_dbuf;
- struct message_rec rec;
- char *ptr;
- struct message_rec prec;
-
- /*
- * Doing kill with a non-positive pid causes messages to be
- * sent to places we don't want.
- */
-
- SMB_ASSERT(pid > 0);
-
- rec.msg_version = MESSAGE_VERSION;
- rec.msg_type = msg_type;
- rec.dest = pid;
- rec.src = sys_getpid();
- rec.len = len;
-
- kbuf = message_key_pid(pid);
+ return msg_ctx->event_ctx;
+}
- dbuf.dptr = (void *)malloc(len + sizeof(rec));
- if (!dbuf.dptr)
- return False;
+struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
+ struct server_id server_id,
+ struct event_context *ev)
+{
+ struct messaging_context *ctx;
+ NTSTATUS status;
- memcpy(dbuf.dptr, &rec, sizeof(rec));
- if (len > 0)
- memcpy((void *)((char*)dbuf.dptr+sizeof(rec)), buf, len);
-
- dbuf.dsize = len + sizeof(rec);
-
- if (duplicates_allowed) {
-
- /* If duplicates are allowed we can just append the message and return. */
-
- /* lock the record for the destination */
- if (timeout) {
- if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
- DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
- return False;
- }
- } else {
- if (tdb_chainlock(tdb, kbuf) == -1) {
- DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
- return False;
- }
- }
- tdb_append(tdb, kbuf, dbuf);
- tdb_chainunlock(tdb, kbuf);
-
- SAFE_FREE(dbuf.dptr);
- errno = 0; /* paranoia */
- return message_notify(pid);
+ if (!(ctx = TALLOC_ZERO_P(mem_ctx, struct messaging_context))) {
+ return NULL;
}
- /* lock the record for the destination */
- if (timeout) {
- if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
- DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
- return False;
- }
- } else {
- if (tdb_chainlock(tdb, kbuf) == -1) {
- DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
- return False;
- }
- }
+ ctx->id = server_id;
+ ctx->event_ctx = ev;
- old_dbuf = tdb_fetch(tdb, kbuf);
+ status = messaging_tdb_init(ctx, ctx, &ctx->local);
- if (!old_dbuf.dptr) {
- /* its a new record */
-
- tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
- tdb_chainunlock(tdb, kbuf);
-
- SAFE_FREE(dbuf.dptr);
- errno = 0; /* paranoia */
- return message_notify(pid);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(2, ("messaging_tdb_init failed: %s\n",
+ nt_errstr(status)));
+ TALLOC_FREE(ctx);
+ return NULL;
}
- /* Not a new record. Check for duplicates. */
-
- for(ptr = (char *)old_dbuf.dptr; ptr < old_dbuf.dptr + old_dbuf.dsize; ) {
- /*
- * First check if the message header matches, then, if it's a non-zero
- * sized message, check if the data matches. If so it's a duplicate and
- * we can discard it. JRA.
- */
-
- if (!memcmp(ptr, &rec, sizeof(rec))) {
- if (!len || (len && !memcmp( ptr + sizeof(rec), buf, len))) {
- tdb_chainunlock(tdb, kbuf);
- DEBUG(10,("message_send_pid_internal: discarding duplicate message.\n"));
- SAFE_FREE(dbuf.dptr);
- SAFE_FREE(old_dbuf.dptr);
- return True;
- }
+#ifdef CLUSTER_SUPPORT
+ if (lp_clustering()) {
+ status = messaging_ctdbd_init(ctx, ctx, &ctx->remote);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(2, ("messaging_ctdb_init failed: %s\n",
+ nt_errstr(status)));
+ TALLOC_FREE(ctx);
+ return NULL;
}
- memcpy(&prec, ptr, sizeof(prec));
- ptr += sizeof(rec) + prec.len;
}
+ ctx->id.vnn = get_my_vnn();
+#endif
- /* we're adding to an existing entry */
+ messaging_register(ctx, NULL, MSG_PING, ping_message);
- tdb_append(tdb, kbuf, dbuf);
- tdb_chainunlock(tdb, kbuf);
-
- SAFE_FREE(old_dbuf.dptr);
- SAFE_FREE(dbuf.dptr);
-
- errno = 0; /* paranoia */
- return message_notify(pid);
-}
+ /* Register some debugging related messages */
-/****************************************************************************
- Send a message to a particular pid - no timeout.
-****************************************************************************/
+ register_msg_pool_usage(ctx);
+ register_dmalloc_msgs(ctx);
+ debug_register_msgs(ctx);
-BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len, BOOL duplicates_allowed)
-{
- return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, 0);
+ return ctx;
}
-/****************************************************************************
- Send a message to a particular pid, with timeout in seconds.
-****************************************************************************/
-
-BOOL message_send_pid_with_timeout(pid_t pid, int msg_type, const void *buf, size_t len,
- BOOL duplicates_allowed, unsigned int timeout)
+struct server_id messaging_server_id(const struct messaging_context *msg_ctx)
{
- return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, timeout);
+ return msg_ctx->id;
}
-/****************************************************************************
- Retrieve all messages for the current process.
-****************************************************************************/
-
-static BOOL retrieve_all_messages(char **msgs_buf, size_t *total_len)
+/*
+ * re-init after a fork
+ */
+NTSTATUS messaging_reinit(struct messaging_context *msg_ctx,
+ struct server_id id)
{
- TDB_DATA kbuf;
- TDB_DATA dbuf;
- TDB_DATA null_dbuf;
+ NTSTATUS status;
- ZERO_STRUCT(null_dbuf);
+ TALLOC_FREE(msg_ctx->local);
- *msgs_buf = NULL;
- *total_len = 0;
+ msg_ctx->id = id;
- kbuf = message_key_pid(sys_getpid());
+ status = messaging_tdb_init(msg_ctx, msg_ctx, &msg_ctx->local);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("messaging_tdb_init failed: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
- if (tdb_chainlock(tdb, kbuf) == -1)
- return False;
+#ifdef CLUSTER_SUPPORT
+ TALLOC_FREE(msg_ctx->remote);
- dbuf = tdb_fetch(tdb, kbuf);
- /*
- * Replace with an empty record to keep the allocated
- * space in the tdb.
- */
- tdb_store(tdb, kbuf, null_dbuf, TDB_REPLACE);
- tdb_chainunlock(tdb, kbuf);
+ if (lp_clustering()) {
+ status = messaging_ctdbd_init(msg_ctx, msg_ctx,
+ &msg_ctx->remote);
- if (dbuf.dptr == NULL || dbuf.dsize == 0) {
- SAFE_FREE(dbuf.dptr);
- return False;
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("messaging_ctdb_init failed: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
}
- *msgs_buf = dbuf.dptr;
- *total_len = dbuf.dsize;
+#endif
- return True;
+ return NT_STATUS_OK;
}
-/****************************************************************************
- Parse out the next message for the current process.
-****************************************************************************/
-static BOOL message_recv(char *msgs_buf, size_t total_len, int *msg_type, pid_t *src, char **buf, size_t *len)
+/*
+ * Register a dispatch function for a particular message type. Allow multiple
+ * registrants
+*/
+NTSTATUS messaging_register(struct messaging_context *msg_ctx,
+ void *private_data,
+ uint32_t msg_type,
+ void (*fn)(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id server_id,
+ DATA_BLOB *data))
{
- struct message_rec rec;
- char *ret_buf = *buf;
-
- *buf = NULL;
- *len = 0;
+ struct messaging_callback *cb;
- if (total_len - (ret_buf - msgs_buf) < sizeof(rec))
- return False;
-
- memcpy(&rec, ret_buf, sizeof(rec));
- ret_buf += sizeof(rec);
+ /*
+ * Only one callback per type
+ */
- if (rec.msg_version != MESSAGE_VERSION) {
- DEBUG(0,("message version %d received (expected %d)\n", rec.msg_version, MESSAGE_VERSION));
- return False;
+ for (cb = msg_ctx->callbacks; cb != NULL; cb = cb->next) {
+ /* we allow a second registration of the same message
+ type if it has a different private pointer. This is
+ needed in, for example, the internal notify code,
+ which creates a new notify context for each tree
+ connect, and expects to receive messages to each of
+ them. */
+ if (cb->msg_type == msg_type && private_data == cb->private_data) {
+ DEBUG(5,("Overriding messaging pointer for type %u - private_data=%p\n",
+ (unsigned)msg_type, private_data));
+ cb->fn = fn;
+ cb->private_data = private_data;
+ return NT_STATUS_OK;
+ }
}
- if (rec.len > 0) {
- if (total_len - (ret_buf - msgs_buf) < rec.len)
- return False;
+ if (!(cb = talloc(msg_ctx, struct messaging_callback))) {
+ return NT_STATUS_NO_MEMORY;
}
- *len = rec.len;
- *msg_type = rec.msg_type;
- *src = rec.src;
- *buf = ret_buf;
+ cb->msg_type = msg_type;
+ cb->fn = fn;
+ cb->private_data = private_data;
- return True;
+ DLIST_ADD(msg_ctx->callbacks, cb);
+ return NT_STATUS_OK;
}
-/****************************************************************************
- Receive and dispatch any messages pending for this process.
- Notice that all dispatch handlers for a particular msg_type get called,
- so you can register multiple handlers for a message.
- *NOTE*: Dispatch functions must be able to cope with incoming
- messages on an *odd* byte boundary.
-****************************************************************************/
-
-void message_dispatch(void)
+/*
+ De-register the function for a particular message type.
+*/
+void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type,
+ void *private_data)
{
- int msg_type;
- pid_t src;
- char *buf;
- char *msgs_buf;
- size_t len, total_len;
- struct dispatch_fns *dfn;
- int n_handled;
-
- if (!received_signal)
- return;
-
- DEBUG(10,("message_dispatch: received_signal = %d\n", received_signal));
-
- received_signal = 0;
-
- if (!retrieve_all_messages(&msgs_buf, &total_len))
- return;
-
- for (buf = msgs_buf; message_recv(msgs_buf, total_len, &msg_type, &src, &buf, &len); buf += len) {
- DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%u\n",
- msg_type, (unsigned int) src));
- n_handled = 0;
- for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
- if (dfn->msg_type == msg_type) {
- DEBUG(10,("message_dispatch: processing message of type %d.\n", msg_type));
- dfn->fn(msg_type, src, len ? (void *)buf : NULL, len);
- n_handled++;
- }
- }
- if (!n_handled) {
- DEBUG(5,("message_dispatch: warning: no handlers registed for "
- "msg_type %d in pid %u\n",
- msg_type, (unsigned int)sys_getpid()));
+ struct messaging_callback *cb, *next;
+
+ for (cb = ctx->callbacks; cb; cb = next) {
+ next = cb->next;
+ if ((cb->msg_type == msg_type)
+ && (cb->private_data == private_data)) {
+ DEBUG(5,("Deregistering messaging pointer for type %u - private_data=%p\n",
+ (unsigned)msg_type, private_data));
+ DLIST_REMOVE(ctx->callbacks, cb);
+ TALLOC_FREE(cb);
}
}
- SAFE_FREE(msgs_buf);
}
-/****************************************************************************
- Register a dispatch function for a particular message type.
- *NOTE*: Dispatch functions must be able to cope with incoming
- messages on an *odd* byte boundary.
-****************************************************************************/
-
-void message_register(int msg_type,
- void (*fn)(int msg_type, pid_t pid, void *buf, size_t len))
+/*
+ Send a message to a particular server
+*/
+NTSTATUS messaging_send(struct messaging_context *msg_ctx,
+ struct server_id server, uint32_t msg_type,
+ const DATA_BLOB *data)
{
- struct dispatch_fns *dfn;
-
- dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
-
- if (dfn != NULL) {
-
- ZERO_STRUCTPN(dfn);
-
- dfn->msg_type = msg_type;
- dfn->fn = fn;
-
- DLIST_ADD(dispatch_fns, dfn);
- }
- else {
-
- DEBUG(0,("message_register: Not enough memory. malloc failed!\n"));
+#ifdef CLUSTER_SUPPORT
+ if (!procid_is_local(&server)) {
+ return msg_ctx->remote->send_fn(msg_ctx, server,
+ msg_type, data,
+ msg_ctx->remote);
}
+#endif
+ return msg_ctx->local->send_fn(msg_ctx, server, msg_type, data,
+ msg_ctx->local);
}
-/****************************************************************************
- De-register the function for a particular message type.
-****************************************************************************/
-
-void message_deregister(int msg_type)
+NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
+ struct server_id server, uint32_t msg_type,
+ const uint8 *buf, size_t len)
{
- struct dispatch_fns *dfn, *next;
-
- for (dfn = dispatch_fns; dfn; dfn = next) {
- next = dfn->next;
- if (dfn->msg_type == msg_type) {
- DLIST_REMOVE(dispatch_fns, dfn);
- SAFE_FREE(dfn);
- }
- }
+ DATA_BLOB blob = data_blob_const(buf, len);
+ return messaging_send(msg_ctx, server, msg_type, &blob);
}
-struct msg_all {
- int msg_type;
- uint32 msg_flag;
- const void *buf;
- size_t len;
- BOOL duplicates;
- int n_sent;
-};
-
-/****************************************************************************
- Send one of the messages for the broadcast.
-****************************************************************************/
-
-static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
+/*
+ Dispatch one messaging_rec
+*/
+void messaging_dispatch_rec(struct messaging_context *msg_ctx,
+ struct messaging_rec *rec)
{
- struct connections_data crec;
- struct msg_all *msg_all = (struct msg_all *)state;
-
- if (dbuf.dsize != sizeof(crec))
- return 0;
-
- memcpy(&crec, dbuf.dptr, sizeof(crec));
-
- if (crec.cnum != -1)
- return 0;
-
- /* Don't send if the receiver hasn't registered an interest. */
-
- if(!(crec.bcast_msg_flags & msg_all->msg_flag))
- return 0;
-
- /* If the msg send fails because the pid was not found (i.e. smbd died),
- * the msg has already been deleted from the messages.tdb.*/
-
- if (!message_send_pid(crec.pid, msg_all->msg_type,
- msg_all->buf, msg_all->len,
- msg_all->duplicates)) {
-
- /* If the pid was not found delete the entry from connections.tdb */
-
- if (errno == ESRCH) {
- DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n",
- (unsigned int)crec.pid, crec.cnum, crec.name));
- tdb_delete(the_tdb, kbuf);
+ struct messaging_callback *cb, *next;
+
+ for (cb = msg_ctx->callbacks; cb != NULL; cb = next) {
+ next = cb->next;
+ if (cb->msg_type == rec->msg_type) {
+ cb->fn(msg_ctx, cb->private_data, rec->msg_type,
+ rec->src, &rec->buf);
+ /* we continue looking for matching messages
+ after finding one. This matters for
+ subsystems like the internal notify code
+ which register more than one handler for
+ the same message type */
}
}
- msg_all->n_sent++;
- return 0;
+ return;
}
-/**
- * Send a message to all smbd processes.
- *
- * It isn't very efficient, but should be OK for the sorts of
- * applications that use it. When we need efficient broadcast we can add
- * it.
- *
- * @param n_sent Set to the number of messages sent. This should be
- * equal to the number of processes, but be careful for races.
- *
- * @retval True for success.
- **/
-BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
- const void *buf, size_t len,
- BOOL duplicates_allowed,
- int *n_sent)
-{
- struct msg_all msg_all;
-
- msg_all.msg_type = msg_type;
- if (msg_type < 1000)
- msg_all.msg_flag = FLAG_MSG_GENERAL;
- else if (msg_type > 1000 && msg_type < 2000)
- msg_all.msg_flag = FLAG_MSG_NMBD;
- else if (msg_type > 2000 && msg_type < 3000)
- msg_all.msg_flag = FLAG_MSG_PRINTING;
- else if (msg_type > 3000 && msg_type < 4000)
- msg_all.msg_flag = FLAG_MSG_SMBD;
- else
- return False;
-
- msg_all.buf = buf;
- msg_all.len = len;
- msg_all.duplicates = duplicates_allowed;
- msg_all.n_sent = 0;
-
- tdb_traverse(conn_tdb, traverse_fn, &msg_all);
- if (n_sent)
- *n_sent = msg_all.n_sent;
- return True;
-}
/** @} **/