first cut at adding full transactions for ctdb to samba3
[bbaumbach/samba-autobuild/.git] / source3 / smbd / server.c
index 9754fab534a8d33910cf4f9918ead684f58fbb0d..05f11f6753c7ab7f43d736af7fc3f5232f94aac7 100644 (file)
@@ -90,9 +90,12 @@ struct messaging_context *smbd_messaging_context(void)
 {
        static struct messaging_context *ctx;
 
-       if (!ctx && !(ctx = messaging_init(NULL, server_id_self(),
-                                          smbd_event_context()))) {
-               smb_panic("Could not init smbd messaging context");
+       if (ctx == NULL) {
+               ctx = messaging_init(NULL, server_id_self(),
+                                    smbd_event_context());
+       }
+       if (ctx == NULL) {
+               DEBUG(0, ("Could not init smbd messaging context.\n"));
        }
        return ctx;
 }
@@ -575,8 +578,6 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
                           MSG_SMB_INJECT_FAULT, msg_inject_fault);
 #endif
 
-       db_tdb2_setup_messaging(smbd_messaging_context(), true);
-
        /* now accept incoming connections - forking a new process
           for each incoming connection */
        DEBUG(2,("waiting for a connection\n"));
@@ -741,17 +742,10 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
                                                                sizeof(remaddr)),
                                                                false);
 
-                               /* Reset the state of the random
-                                * number generation system, so
-                                * children do not get the same random
-                                * numbers as each other */
-
-                               set_need_random_reseed();
-                               /* tdb needs special fork handling - remove
-                                * CLEAR_IF_FIRST flags */
-                               if (tdb_reopen_all(1) == -1) {
-                                       DEBUG(0,("tdb_reopen_all failed.\n"));
-                                       smb_panic("tdb_reopen_all failed");
+                               if (!reinit_after_fork(
+                                           smbd_messaging_context(), true)) {
+                                       DEBUG(0,("reinit_after_fork() failed\n"));
+                                       smb_panic("reinit_after_fork() failed");
                                }
 
                                return True;
@@ -1226,10 +1220,13 @@ extern void build_options(bool screen);
                exit(1);
        }
 
-       /*
-        * Do this before reload_services.
-        */
-       db_tdb2_setup_messaging(NULL, false);
+       if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
+               DEBUG(0, ("error opening config file\n"));
+               exit(1);
+       }
+
+       if (smbd_messaging_context() == NULL)
+               exit(1);
 
        if (!reload_services(False))
                return(-1);     
@@ -1285,10 +1282,12 @@ extern void build_options(bool screen);
        if (is_daemon)
                pidfile_create("smbd");
 
-       /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
-
-       if (smbd_messaging_context() == NULL)
+       if (!reinit_after_fork(smbd_messaging_context(), false)) {
+               DEBUG(0,("reinit_after_fork() failed\n"));
                exit(1);
+       }
+
+       /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
 
        if (smbd_memcache() == NULL) {
                exit(1);
@@ -1323,7 +1322,7 @@ extern void build_options(bool screen);
 
        namecache_enable();
 
-       if (!W_ERROR_IS_OK(init_registry()))
+       if (!W_ERROR_IS_OK(registry_init_full()))
                exit(1);
 
 #if 0
@@ -1344,8 +1343,10 @@ extern void build_options(bool screen);
           smbd is launched via inetd and we fork a copy of 
           ourselves here */
 
-       if ( is_daemon && !interactive )
-               start_background_queue(); 
+       if (is_daemon && !interactive
+           && lp_parm_bool(-1, "smbd", "backgroundqueue", true)) {
+               start_background_queue();
+       }
 
        if (!open_sockets_smbd(is_daemon, interactive, ports))
                exit(1);
@@ -1382,18 +1383,13 @@ extern void build_options(bool screen);
        /* Setup aio signal handler. */
        initialize_async_io_handler();
 
-       /*
-        * For clustering, we need to re-init our ctdbd connection after the
-        * fork
-        */
-       if (!NT_STATUS_IS_OK(messaging_reinit(smbd_messaging_context())))
-               exit(1);
-
        /* register our message handlers */
        messaging_register(smbd_messaging_context(), NULL,
                           MSG_SMB_FORCE_TDIS, msg_force_tdis);
        messaging_register(smbd_messaging_context(), NULL,
                           MSG_SMB_RELEASE_IP, msg_release_ip);
+       messaging_register(smbd_messaging_context(), NULL,
+                          MSG_SMB_CLOSE_FILE, msg_close_file);
 
        if ((lp_keepalive() != 0)
            && !(event_add_idle(smbd_event_context(), NULL,