[PATCH] Extending the debugging system with per-class logfiles

Stefan Metzmacher metze at samba.org
Wed Dec 19 23:28:30 UTC 2018


Am 20.12.18 um 00:19 schrieb Douglas Bagnall via samba-technical:
>> On Mon, Dec 17, 2018 at 02:14:40PM -0800, Jeremy Allison wrote:
>>> Great work Ralph !
> 
> Yes. The one thing missing is a WHATSNEW patch.

While I haven't looked at the code, I like the concept:-)

And I think it would be useful if someone could finish the attached
patch, that lets each 'samba' task use it's own log file by default.

I guess it won't work correct for all process models.
It should be in a helper function called from standard_new_task()
and prefork_fork_master().

metze
-------------- next part --------------
From 48bffaea1799bb3014ac62aaa87396e63ae831a7 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 14 Jan 2018 14:51:39 +0100
Subject: [PATCH] s4: setup logging for tasks to use their own logfile

---
 source4/smbd/service_task.c | 45 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/source4/smbd/service_task.c b/source4/smbd/service_task.c
index d911027db0a7..075c9668038d 100644
--- a/source4/smbd/service_task.c
+++ b/source4/smbd/service_task.c
@@ -24,6 +24,7 @@
 #include "lib/messaging/irpc.h"
 #include "param/param.h"
 #include "librpc/gen_ndr/ndr_irpc_c.h"
+#include "dynconfig/dynconfig.h"
 
 /*
   terminate a task service
@@ -117,6 +118,10 @@ NTSTATUS task_server_startup(struct tevent_context *event_ctx,
 			     int from_parent_fd)
 {
 	struct task_state *state;
+	char *config_logfile = NULL;
+	char *logdir = NULL;
+	char *logfile = NULL;
+	NTSTATUS status = NT_STATUS_INTERNAL_ERROR;
 
 	state = talloc(event_ctx, struct task_state);
 	NT_STATUS_HAVE_NO_MEMORY(state);
@@ -124,11 +129,49 @@ NTSTATUS task_server_startup(struct tevent_context *event_ctx,
 	state->service_details = service_details;
 	state->model_ops = model_ops;
 
+	config_logfile = lpcfg_logfile(lp_ctx, state);
+	if (config_logfile != NULL) {
+		char *end = NULL;
+
+		logdir = talloc_strdup(state, config_logfile);
+		if (logdir == NULL) {
+			status = NT_STATUS_NO_MEMORY;
+			goto done;
+		}
+
+		end = strrchr_m(logdir, '/');
+		if (end != NULL) {
+			*end = '\0';
+		}
+	} else {
+		logdir = talloc_strdup(state, get_dyn_LOGFILEBASE());
+		if (logdir == NULL) {
+			status = NT_STATUS_NO_MEMORY;
+			goto done;
+		}
+	}
+
+	logfile = talloc_asprintf(state, "%s/%s.log", logdir, service_name);
+	if (logfile == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto done;
+	}
+
+	lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
+	debug_set_logfile(logfile);
+	reopen_logs_internal();
+
 	state->model_ops->new_task(event_ctx, lp_ctx, service_name,
 			           task_server_callback, state, service_details,
 				   from_parent_fd);
 
-	return NT_STATUS_OK;
+	status = NT_STATUS_OK;
+
+done:
+	TALLOC_FREE(config_logfile);
+	TALLOC_FREE(logfile);
+	TALLOC_FREE(logdir);
+	return status;
 }
 
 /*
-- 
2.17.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181220/ff612c6c/signature.sig>


More information about the samba-technical mailing list