]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:process_prefork: create new messaging context for the master process
authorJule Anger <janger@samba.org>
Wed, 1 Mar 2023 10:02:00 +0000 (10:02 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 Jul 2023 20:04:29 +0000 (20:04 +0000)
In order to allow the before_loop() hook to register messages or event
handlers, we need to fix up task->event_ctx and create a new
task->msg_ctx. It also means the struct task_server pointer
changes in the master before_loop() hook.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Jule Anger <janger@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/samba/process_prefork.c

index 1bad15ee8932b678d3fb9bec1b1841b91e6c0576..47bd23f5e234440d568c83b2a5f4f0ed18a8b92b 100644 (file)
@@ -413,7 +413,37 @@ static void prefork_fork_master(
         * and restarting of died workers
         */
        if (task != NULL && service_details->before_loop != NULL) {
-               service_details->before_loop(task);
+               struct task_server *task_copy = NULL;
+
+               /*
+                * We need to use ev as parent in order to
+                * keep everything alive during the loop
+                */
+               task_copy = talloc(ev, struct task_server);
+               if (task_copy == NULL) {
+                       TALLOC_FREE(ev);
+                       TALLOC_FREE(ev2);
+                       exit(127);
+               }
+               *task_copy = *task;
+
+               /*
+                * In order to allow the before_loop() hook
+                * to register messages or event handlers,
+                * we need to fix up task->event_ctx
+                * and create a new task->msg_ctx
+                */
+               task_copy->event_ctx = ev;
+               task_copy->msg_ctx = imessaging_init(task_copy,
+                                               task_copy->lp_ctx,
+                                               task_copy->server_id,
+                                               task_copy->event_ctx);
+               if (task_copy->msg_ctx == NULL) {
+                       TALLOC_FREE(ev);
+                       TALLOC_FREE(ev2);
+                       exit(127);
+               }
+               service_details->before_loop(task_copy);
        }
 
        /*