Allow reinit_after_fork to be called safely from within swat and other binaries that...
authorJeremy Allison <jra@samba.org>
Thu, 15 Jan 2009 23:50:50 +0000 (15:50 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 15 Jan 2009 23:50:50 +0000 (15:50 -0800)
an event context or a msg context. Fixes crash bug in swat.
Jeremy.

source/lib/dummysmbd.c
source/lib/util.c

index 5c624bdebfb9e86cbe67506e8c8b47ee7ede58d5..f0fd18c87aa63cf4ef9112b612940383caa89285 100644 (file)
@@ -59,7 +59,12 @@ bool change_to_root_user(void)
 
 struct event_context *smbd_event_context(void)
 {
-       return NULL;
+       static struct event_context *ev;
+
+       if (!ev) {
+               ev = event_context_init(NULL);
+       }
+       return ev;
 }
 
 struct messaging_context *smbd_messaging_context(void)
index 262d37f8c4ff48801bbcc82f6e7680d61b4defc4..5ec6f2641035af5c958e054b206cb040869685be 100644 (file)
@@ -1055,18 +1055,22 @@ bool reinit_after_fork(struct messaging_context *msg_ctx,
                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;
+       if (msg_ctx) {
+               /*
+                * 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;
+               }
        }
 
-       event_context_reinit(ev_ctx);
+       if (ev_ctx) {
+               event_context_reinit(ev_ctx);
+       }
 
        return true;
 }