From 1472e4c9dbf5eb98f7074d17bf4e3dabfec14fd0 Mon Sep 17 00:00:00 2001 From: Jule Anger Date: Wed, 1 Mar 2023 10:02:00 +0000 Subject: [PATCH] s4:process_prefork: create new messaging context for the master process 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 Signed-off-by: Jule Anger Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/samba/process_prefork.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/source4/samba/process_prefork.c b/source4/samba/process_prefork.c index 1bad15ee893..47bd23f5e23 100644 --- a/source4/samba/process_prefork.c +++ b/source4/samba/process_prefork.c @@ -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); } /* -- 2.11.4.GIT