From 7299ebb1215776b19f5094e861a21c7df06220f2 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 26 Nov 2020 14:21:58 +0100 Subject: [PATCH] s4: install tevent tracing hooks to trigger logfile rotation BUG: https://bugzilla.samba.org/show_bug.cgi?id=14248 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (backported from commit 516c2a04a242a539f9fbddb2822295fee233644c) [slow@samba.org: process_prefork.c has additional include in master] --- source4/smbd/process_prefork.c | 13 +++++++++++++ source4/smbd/server.c | 17 +++++++++++++++++ source4/smbd/wscript_build | 5 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/source4/smbd/process_prefork.c b/source4/smbd/process_prefork.c index 5667fb5f1ef..950db6a1c7d 100644 --- a/source4/smbd/process_prefork.c +++ b/source4/smbd/process_prefork.c @@ -44,6 +44,7 @@ #include "ldb_wrap.h" #include "lib/util/tfork.h" #include "lib/messaging/irpc.h" +#include "server_util.h" #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -243,6 +244,7 @@ static void prefork_fork_master( struct tevent_context *ev2; struct task_server *task = NULL; struct process_details pd = initial_process_details; + struct samba_tevent_trace_state *samba_tevent_trace_state = NULL; int control_pipe[2]; t = tfork_create(); @@ -321,6 +323,17 @@ static void prefork_fork_master( */ ev2 = s4_event_context_init(NULL); + samba_tevent_trace_state = create_samba_tevent_trace_state(ev2); + if (samba_tevent_trace_state == NULL) { + TALLOC_FREE(ev); + TALLOC_FREE(ev2); + exit(127); + } + + tevent_set_trace_callback(ev2, + samba_tevent_trace_callback, + samba_tevent_trace_state); + /* setup this new connection: process will bind to it's sockets etc * * While we can use ev for the child, which has been re-initialised diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 95acb99b86c..c92988352f2 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -46,6 +46,7 @@ #include "lib/util/tfork.h" #include "dsdb/samdb/ldb_modules/util.h" #include "lib/util/server_id.h" +#include "server_util.h" #ifdef HAVE_PTHREAD #include @@ -572,6 +573,7 @@ static int binary_smbd_main(const char *binary_name, }; struct server_state *state = NULL; struct tevent_signal *se = NULL; + struct samba_tevent_trace_state *samba_tevent_trace_state = NULL; setproctitle("root process"); @@ -727,6 +729,21 @@ static int binary_smbd_main(const char *binary_name, talloc_set_destructor(state->event_ctx, event_ctx_destructor); + samba_tevent_trace_state = create_samba_tevent_trace_state(state); + if (samba_tevent_trace_state == NULL) { + exit_daemon("Samba failed to setup tevent tracing state", + ENOTTY); + /* + * return is never reached but is here to satisfy static + * checkers + */ + return 1; + } + + tevent_set_trace_callback(state->event_ctx, + samba_tevent_trace_callback, + samba_tevent_trace_state); + if (opt_interactive) { /* terminate when stdin goes away */ stdin_event_flags = TEVENT_FD_READ; diff --git a/source4/smbd/wscript_build b/source4/smbd/wscript_build index 146098ec8e4..14267c1c9a5 100644 --- a/source4/smbd/wscript_build +++ b/source4/smbd/wscript_build @@ -25,7 +25,8 @@ bld.SAMBA_BINARY('samba', source='server.c', subsystem_name='service', deps='''events process_model service samba-hostconfig samba-util POPT_SAMBA - popt gensec registry ntvfs share cluster COMMON_SCHANNEL SECRETS''', + popt gensec registry ntvfs share cluster COMMON_SCHANNEL SECRETS + samba_server_util''', pyembed=True, install_path='${SBINDIR}', enabled=bld.AD_DC_BUILD_IS_ENABLED() @@ -52,6 +53,6 @@ bld.SAMBA_MODULE('process_model_prefork', source='process_prefork.c', subsystem='process_model', init_function='process_model_prefork_init', - deps='MESSAGING events ldbsamba cluster samba-sockets process_model messages_dgm', + deps='MESSAGING events ldbsamba cluster samba-sockets process_model messages_dgm samba_server_util', internal_module=False ) -- 2.47.2