Use the proper boolean constants.
[bbaumbach/samba-autobuild/.git] / source / lib / messages.c
index 056286f89a0b1ef8816391bb9200b2bede435982..5cd575466fae33aeff86432227f2cf126df3e6a5 100644 (file)
@@ -8,7 +8,7 @@
    
    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,
@@ -17,8 +17,7 @@
    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/>.
 */
 
 /**
@@ -96,12 +95,12 @@ struct msg_all {
  Send one of the messages for the broadcast.
 ****************************************************************************/
 
-static int traverse_fn(TDB_CONTEXT *the_tdb,
+static int traverse_fn(struct db_record *rec,
                       const struct connections_key *ckey,
                       const struct connections_data *crec,
-                      void *private_data)
+                      void *state)
 {
-       struct msg_all *msg_all = (struct msg_all *)private_data;
+       struct msg_all *msg_all = (struct msg_all *)state;
        NTSTATUS status;
 
        if (crec->cnum != -1)
@@ -120,20 +119,14 @@ static int traverse_fn(TDB_CONTEXT *the_tdb,
                                    (uint8 *)msg_all->buf, msg_all->len);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
-
-               TDB_DATA key;
                
-               /* If the pid was not found delete the entry from
-                * connections.tdb */
-
-               DEBUG(2,("pid %s doesn't exist - deleting connections "
-                        "%d [%s]\n", procid_str_static(&crec->pid),
-                        crec->cnum, crec->servicename));
+               /* If the pid was not found delete the entry from connections.tdb */
 
-               key.dptr = (uint8 *)ckey;
-               key.dsize = sizeof(*ckey);
+               DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
+                        procid_str_static(&crec->pid), crec->cnum,
+                        crec->servicename));
 
-               tdb_delete(the_tdb, key);
+               rec->delete_rec(rec);
        }
        msg_all->n_sent++;
        return 0;
@@ -151,7 +144,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb,
  *
  * @retval True for success.
  **/
-BOOL message_send_all(struct messaging_context *msg_ctx,
+bool message_send_all(struct messaging_context *msg_ctx,
                      int msg_type,
                      const void *buf, size_t len,
                      int *n_sent)
@@ -205,10 +198,25 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
        status = messaging_tdb_init(ctx, ctx, &ctx->local);
 
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("message_init failed: %s\n", nt_errstr(status)));
+               DEBUG(0, ("messaging_tdb_init failed: %s\n",
+                         nt_errstr(status)));
                TALLOC_FREE(ctx);
+               return NULL;
        }
 
+#ifdef CLUSTER_SUPPORT
+       if (lp_clustering()) {
+               status = messaging_ctdbd_init(ctx, ctx, &ctx->remote);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("messaging_ctdb_init failed: %s\n",
+                                 nt_errstr(status)));
+                       TALLOC_FREE(ctx);
+                       return NULL;
+               }
+       }
+#endif
+
        messaging_register(ctx, NULL, MSG_PING, ping_message);
 
        /* Register some debugging related messages */
@@ -220,6 +228,34 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
        return ctx;
 }
 
+/*
+ * re-init after a fork
+ */
+NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
+{
+#ifdef CLUSTER_SUPPORT
+
+       TALLOC_FREE(msg_ctx->remote);
+
+       if (lp_clustering()) {
+               NTSTATUS status;
+
+               status = messaging_ctdbd_init(msg_ctx, msg_ctx,
+                                             &msg_ctx->remote);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("messaging_ctdb_init failed: %s\n",
+                                 nt_errstr(status)));
+                       return status;
+               }
+       }
+
+#endif
+
+       return NT_STATUS_OK;
+}
+
+
 /*
  * Register a dispatch function for a particular message type. Allow multiple
  * registrants
@@ -284,6 +320,13 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
                        struct server_id server, uint32_t msg_type,
                        const DATA_BLOB *data)
 {
+#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);
 }