util: add reinit_after_fork() function
authorStefan Metzmacher <metze@samba.org>
Tue, 15 Apr 2008 08:36:15 +0000 (10:36 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 21 Apr 2008 06:40:39 +0000 (08:40 +0200)
metze
(cherry picked from commit 5f6c3a4f6db68c985884cbe9401a4dbe515f756b)

source/lib/util.c

index ecd8951f946d0d7dc2ead94c3595975f9a7ed347..3b2d37526c8551f68fa923aa82653868dd64c8c4 100644 (file)
@@ -990,6 +990,36 @@ void become_daemon(bool Fork, bool no_process_group)
                                  attach it to the logfile */
 }
 
+bool reinit_after_fork(struct messaging_context *msg_ctx)
+{
+       NTSTATUS status;
+
+       /* 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 */
+       if (tdb_reopen_all(1) == -1) {
+               DEBUG(0,("tdb_reopen_all failed.\n"));
+               return false;
+       }
+
+       /*
+        * For clustering, we need to re-init our ctdbd connection after the
+        * fork
+        */
+       status = messaging_reinit(msg_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("messaging_reinit() failed: %s\n",
+                        nt_errstr(status)));
+               return false;
+       }
+
+       return true;
+}
+
 /****************************************************************************
  Put up a yes/no prompt.
 ****************************************************************************/