s4: messaging. Add imessaging_reinit_all() function.
authorJeremy Allison <jra@samba.org>
Wed, 29 Mar 2017 18:11:37 +0000 (11:11 -0700)
committerVolker Lendecke <vl@samba.org>
Fri, 31 Mar 2017 12:48:17 +0000 (14:48 +0200)
Ensure it is called from process_standard.c after
every fork().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Mar 31 14:48:17 CEST 2017 on sn-devel-144

source4/lib/messaging/messaging.c
source4/lib/messaging/messaging.h
source4/smbd/process_standard.c
source4/smbd/wscript_build

index 80ef597ed48d951a6d298482403103a206111acc..844466d41c08239ee8b459c97a5aa6cec0a941a6 100644 (file)
@@ -271,6 +271,49 @@ void imessaging_dgm_unref_all(void)
        }
 }
 
+static NTSTATUS imessaging_reinit(struct imessaging_context *msg)
+{
+       int ret = -1;
+
+       TALLOC_FREE(msg->msg_dgm_ref);
+
+       msg->server_id.pid = getpid();
+
+       msg->msg_dgm_ref = messaging_dgm_ref(msg,
+                               msg->ev,
+                               &msg->server_id.unique_id,
+                               msg->sock_dir,
+                               msg->lock_dir,
+                               imessaging_dgm_recv,
+                               msg,
+                               &ret);
+
+       if (msg->msg_dgm_ref == NULL) {
+               DEBUG(2, ("messaging_dgm_ref failed: %s\n",
+                       strerror(ret)));
+               return map_nt_error_from_unix_common(ret);
+       }
+
+       server_id_db_reinit(msg->names, msg->server_id);
+       return NT_STATUS_OK;
+}
+
+/*
+ * Must be called after a fork.
+ */
+NTSTATUS imessaging_reinit_all(void)
+{
+       struct imessaging_context *msg = NULL;
+
+       for (msg = msg_ctxs; msg != NULL; msg = msg->next) {
+               NTSTATUS status = imessaging_reinit(msg);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+       }
+       return NT_STATUS_OK;
+}
+
 /*
   create the listening socket and setup the dispatcher
 */
index 3b76b45e5c466d205593e595c21f671b957fecac..e587fdfb3aa0847c1f685303ca796d49fb88e3db 100644 (file)
@@ -45,6 +45,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
                                           struct server_id server_id,
                                           struct tevent_context *ev);
 void imessaging_dgm_unref_all(void);
+NTSTATUS imessaging_reinit_all(void);
 int imessaging_cleanup(struct imessaging_context *msg);
 struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
                                           struct loadparm_context *lp_ctx,
index 18946577e568560070356baa50788a5916c4a3aa..ca93f93ce55535e1631247e0fdd881a9abfc4d7d 100644 (file)
@@ -28,6 +28,7 @@
 #include "cluster/cluster.h"
 #include "param/param.h"
 #include "ldb_wrap.h"
+#include "lib/messaging/messaging.h"
 
 struct standard_child_state {
        const char *name;
@@ -270,6 +271,12 @@ static void standard_accept_connection(struct tevent_context *ev,
        /* tdb needs special fork handling */
        ldb_wrap_fork_hook();
 
+       /* Must be done after a fork() to reset messaging contexts. */
+       status = imessaging_reinit_all();
+       if (!NT_STATUS_IS_OK(status)) {
+               smb_panic("Failed to re-initialise imessaging after fork");
+       }
+
        tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
                      standard_pipe_handler, NULL);
        if (child_pipe[1] != -1) {
@@ -309,6 +316,7 @@ static void standard_new_task(struct tevent_context *ev,
                              void *private_data)
 {
        pid_t pid;
+       NTSTATUS status;
        struct standard_child_state *state;
 
        state = setup_standard_child_pipe(ev, service_name);
@@ -346,6 +354,12 @@ static void standard_new_task(struct tevent_context *ev,
        /* ldb/tdb need special fork handling */
        ldb_wrap_fork_hook();
 
+       /* Must be done after a fork() to reset messaging contexts. */
+       status = imessaging_reinit_all();
+       if (!NT_STATUS_IS_OK(status)) {
+               smb_panic("Failed to re-initialise imessaging after fork");
+       }
+
        tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
                      standard_pipe_handler, NULL);
        if (child_pipe[1] != -1) {
index 98220d043588b13edc762728ab99984a72ac06c0..ca2039694a4c2696759aaa23118fe57a7ba98e4b 100644 (file)
@@ -40,7 +40,7 @@ bld.SAMBA_MODULE('process_model_standard',
                  source='process_standard.c',
                  subsystem='process_model',
                  init_function='process_model_standard_init',
-                 deps='events ldbsamba process_model samba-sockets cluster',
+                 deps='MESSAGING events ldbsamba process_model samba-sockets cluster',
                  internal_module=False
                  )