s4: setup logging for tasks to use their own logfile
authorRalph Boehme <slow@samba.org>
Sun, 14 Jan 2018 13:51:39 +0000 (14:51 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Oct 2019 13:33:03 +0000 (14:33 +0100)
source4/smbd/service_task.c

index d911027db0a7c0d1625aa043a33666a09ebd264a..075c9668038d1f92b9bec418d9e73d8bd188596e 100644 (file)
@@ -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;
 }
 
 /*