messages_ctdbd: make sure a ctdbd connection is only used in the process that created it
authorStefan Metzmacher <metze@samba.org>
Mon, 14 Apr 2008 23:18:06 +0000 (01:18 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 21 Apr 2008 06:40:38 +0000 (08:40 +0200)
metze
(cherry picked from commit 259786980a3a65fa67a4de12a65d33095fa53ce2)

source/lib/messages_ctdbd.c

index f1a02e6af9fdb3d6cc8ff86c2c888b17b531b7b5..0c8a2aa8e4404c9096969b53f64b78e3348fad78 100644 (file)
@@ -35,10 +35,18 @@ struct messaging_ctdbd_context {
  * This is a Samba3 hack/optimization. Routines like process_exists need to
  * talk to ctdbd, and they don't get handed a messaging context.
  */
-struct ctdbd_connection *global_ctdbd_connection;
+static struct ctdbd_connection *global_ctdbd_connection;
+static int global_ctdb_connection_pid;
 
 struct ctdbd_connection *messaging_ctdbd_connection(void)
 {
+       if (global_ctdb_connection_pid != getpid()) {
+               DEBUG(0,("messaging_ctdbd_connection():"
+                        "valid for pid[%d] but it's [%d]\n",
+                        global_ctdb_connection_pid, getpid()));
+               smb_panic("messaging_ctdbd_connection() invalid process\n");
+       }
+
        return global_ctdbd_connection;
 }
 
@@ -66,6 +74,7 @@ static int messaging_ctdbd_destructor(struct messaging_ctdbd_context *ctx)
        /*
         * The global connection just went away
         */
+       global_ctdb_connection_pid = 0;
        global_ctdbd_connection = NULL;
        return 0;
 }
@@ -107,6 +116,7 @@ NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
                return status;
        }
 
+       global_ctdb_connection_pid = getpid();
        global_ctdbd_connection = ctx->conn;
        talloc_set_destructor(ctx, messaging_ctdbd_destructor);