smbd/winbindd: Do an early check if ctdbd is functional
authorVolker Lendecke <vl@samba.org>
Thu, 31 Jan 2013 10:15:09 +0000 (11:15 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 17 Oct 2013 21:20:45 +0000 (23:20 +0200)
This will avoid panic calls when smbd and winbind is started in cluster
mode before ctdb is functional. It still logs something sane at debug
level 0, but it does not panic and core anymore.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/include/ctdbd_conn.h
source3/lib/ctdbd_conn.c
source3/smbd/server.c
source3/winbindd/winbindd.c

index 64cb1d5ade7766d8a7995103c20bce5d6101bac2..ce5c8ba007a65e954aea620329debf37d4a79960 100644 (file)
@@ -89,5 +89,6 @@ NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
 NTSTATUS ctdb_watch_us(struct ctdbd_connection *conn);
 NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn);
 NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid);
+NTSTATUS ctdbd_probe(void);
 
 #endif /* _CTDBD_CONN_H */
index 70833cb91d042b9fff7eb0134bb2cc1d004a36ee..6ab4bbe70466e5e875fa18d8f27698fe51ec59a6 100644 (file)
@@ -1822,8 +1822,32 @@ NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn)
        return status;
 }
 
+NTSTATUS ctdbd_probe(void)
+{
+       /*
+        * Do a very early check if ctdbd is around to avoid an abort and core
+        * later
+        */
+       struct ctdbd_connection *conn = NULL;
+       NTSTATUS status;
+
+       status = ctdbd_messaging_connection(talloc_tos(), &conn);
+
+       /*
+        * We only care if we can connect.
+        */
+       TALLOC_FREE(conn);
+
+       return status;
+}
+
 #else
 
+NTSTATUS ctdbd_probe(void)
+{
+       return NT_STATUS_OK;
+}
+
 NTSTATUS ctdbd_messaging_send_blob(struct ctdbd_connection *conn,
                                   uint32_t dst_vnn, uint64_t dst_srvid,
                                   const uint8_t *buf, size_t buflen)
index d3cd33ec90bd1e3421a4b43351ba50b388c823a5..3536f18cf4983aab738212e5e793fd110f3b242d 100644 (file)
@@ -1214,6 +1214,17 @@ extern void build_options(bool screen);
                exit(1);
        }
 
+       if (lp_clustering()) {
+               NTSTATUS status;
+
+               status = ctdbd_probe();
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("clustering=yes but ctdbd connect failed: "
+                                 "%s\n", nt_errstr(status)));
+                       exit(1);
+               }
+       }
+
        /* Init the security context and global current_user */
        init_sec_ctx();
 
index 31280c216b86e4784e73ff6a245f40888d61fa62..b8b9c21170f56f332e9e2e1b88dfa2a4dc29235c 100644 (file)
@@ -37,6 +37,7 @@
 #include "auth.h"
 #include "messages.h"
 #include "../lib/util/pidfile.h"
+#include "ctdbd_conn.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -1464,6 +1465,17 @@ int main(int argc, char **argv, char **envp)
                exit(1);
        }
 
+       if (lp_clustering()) {
+               NTSTATUS status;
+
+               status = ctdbd_probe();
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("clustering=yes but ctdbd connect failed: "
+                                 "%s\n", nt_errstr(status)));
+                       exit(1);
+               }
+       }
+
        /* Initialise messaging system */
 
        if (winbind_messaging_context() == NULL) {