s3:lib/conn_tdb: implement connections_forall_read() based on smbXsrv_*_global_traverse()
[kai/samba.git] / source3 / lib / messages_ctdbd.c
index 7d182a57d8ac8126f37207406d57ee94654cd6d9..7899477ba09119caed647375e00483a7caaf2f7e 100644 (file)
@@ -2,26 +2,45 @@
    Unix SMB/CIFS implementation.
    Samba internal messaging functions
    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 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 "includes.h"
+#include "messages.h"
+#include "util_tdb.h"
 
 #ifdef CLUSTER_SUPPORT
 
-#include "librpc/gen_ndr/messaging.h"
+/*
+ * It is not possible to include ctdb.h and tdb_compat.h (included via
+ * some other include above) without warnings. This fixes those
+ * warnings.
+ */
+
+#ifdef typesafe_cb
+#undef typesafe_cb
+#endif
+
+#ifdef typesafe_cb_preargs
+#undef typesafe_cb_preargs
+#endif
+
+#ifdef typesafe_cb_postargs
+#undef typesafe_cb_postargs
+#endif
+
 #include "ctdb.h"
 #include "ctdb_private.h"
 #include "ctdbd_conn.h"
@@ -40,6 +59,10 @@ static int global_ctdb_connection_pid;
 
 struct ctdbd_connection *messaging_ctdbd_connection(void)
 {
+       if (!lp_clustering()) {
+               return NULL;
+       }
+
        if (global_ctdb_connection_pid == 0 &&
            global_ctdbd_connection == NULL) {
                struct event_context *ev;
@@ -50,12 +73,11 @@ struct ctdbd_connection *messaging_ctdbd_connection(void)
                        DEBUG(0,("event_context_init failed\n"));
                }
 
-               msg = messaging_init(NULL, procid_self(), ev);
+               msg = messaging_init(NULL, ev);
                if (!msg) {
                        DEBUG(0,("messaging_init failed\n"));
+                       return NULL;
                }
-
-               db_tdb2_setup_messaging(msg, false);
        }
 
        if (global_ctdb_connection_pid != getpid()) {
@@ -81,7 +103,7 @@ static NTSTATUS messaging_ctdb_send(struct messaging_context *msg_ctx,
        msg.msg_version = MESSAGE_VERSION;
        msg.msg_type    = msg_type;
        msg.dest        = pid;
-       msg.src         = procid_self();
+       msg.src         = msg_ctx->id;
        msg.buf         = *data;
 
        return ctdbd_messaging_send(ctx->conn, pid.vnn, pid.pid, &msg);
@@ -105,12 +127,12 @@ NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
        struct messaging_ctdbd_context *ctx;
        NTSTATUS status;
 
-       if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) {
+       if (!(result = talloc(mem_ctx, struct messaging_backend))) {
                DEBUG(0, ("talloc failed\n"));
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (!(ctx = TALLOC_P(result, struct messaging_ctdbd_context))) {
+       if (!(ctx = talloc(result, struct messaging_ctdbd_context))) {
                DEBUG(0, ("talloc failed\n"));
                TALLOC_FREE(result);
                return NT_STATUS_NO_MEMORY;
@@ -156,4 +178,9 @@ NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
+struct ctdbd_connection *messaging_ctdbd_connection(void)
+{
+       return NULL;
+}
+
 #endif