diff options
-rw-r--r-- | source3/printing/queue_process.c | 15 | ||||
-rw-r--r-- | source3/printing/queue_process.h | 3 | ||||
-rw-r--r-- | source3/printing/spoolssd.c | 63 |
3 files changed, 55 insertions, 26 deletions
diff --git a/source3/printing/queue_process.c b/source3/printing/queue_process.c index 82fd70d36d..a56baaf6b7 100644 --- a/source3/printing/queue_process.c +++ b/source3/printing/queue_process.c @@ -81,6 +81,14 @@ static bool printing_subsystem_queue_tasks(struct tevent_context *ev_ctx, return true; } +static void bq_reopen_logs(char *logfile) +{ + if (logfile) { + lp_set_logfile(logfile); + } + reopen_logs(); +} + static void bq_sig_term_handler(struct tevent_context *ev, struct tevent_signal *se, int signum, @@ -119,6 +127,7 @@ static void bq_sig_hup_handler(struct tevent_context *ev, DEBUG(1, ("Reloading pcap cache after SIGHUP\n")); pcap_cache_reload(ev, msg_ctx, &reload_pcap_change_notify); + bq_reopen_logs(NULL); } static void bq_setup_sig_hup_handler(struct tevent_context *ev, @@ -164,7 +173,8 @@ static void printing_pause_fd_handler(struct tevent_context *ev, main thread of the background lpq updater ****************************************************************************/ pid_t start_background_queue(struct tevent_context *ev, - struct messaging_context *msg_ctx) + struct messaging_context *msg_ctx, + char *logfile) { pid_t pid; @@ -206,6 +216,7 @@ pid_t start_background_queue(struct tevent_context *ev, smb_panic("reinit_after_fork() failed"); } + bq_reopen_logs(logfile); bq_setup_sig_term_handler(); bq_setup_sig_hup_handler(ev, msg_ctx); @@ -273,7 +284,7 @@ bool printing_subsystem_init(struct tevent_context *ev_ctx, } else if (start_daemons && background_queue) { - pid = start_background_queue(ev_ctx, msg_ctx); + pid = start_background_queue(ev_ctx, msg_ctx, NULL); } else { bool ret; diff --git a/source3/printing/queue_process.h b/source3/printing/queue_process.h index 5f282c4462..b769364952 100644 --- a/source3/printing/queue_process.h +++ b/source3/printing/queue_process.h @@ -28,4 +28,5 @@ void printing_subsystem_update(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, bool force); pid_t start_background_queue(struct tevent_context *ev, - struct messaging_context *msg); + struct messaging_context *msg, + char *logfile); diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c index 79731ee948..038d3dbc12 100644 --- a/source3/printing/spoolssd.c +++ b/source3/printing/spoolssd.c @@ -97,46 +97,43 @@ static void spoolss_prefork_config(void) static void spoolss_reopen_logs(int child_id) { char *lfile = lp_logfile(); - char *extension; + char *ext; int rc; if (child_id) { - rc = asprintf(&extension, ".%s.%d", DAEMON_NAME, child_id); + rc = asprintf(&ext, ".%s.%d", DAEMON_NAME, child_id); } else { - rc = asprintf(&extension, ".%s", DAEMON_NAME); + rc = asprintf(&ext, ".%s", DAEMON_NAME); } if (rc == -1) { /* if we can't allocate, set it to NULL * and logging will flow in the original file */ - extension = NULL; + ext = NULL; } + rc = 0; if (lfile == NULL || lfile[0] == '\0') { - rc = asprintf(&lfile, "%s/log%s", get_dyn_LOGFILEBASE(), - extension?extension:""); - if (rc > 0) { - lp_set_logfile(lfile); - SAFE_FREE(lfile); - } + rc = asprintf(&lfile, "%s/log%s", + get_dyn_LOGFILEBASE(), ext?ext:""); } else { - rc = 0; - if (extension && strstr(lfile, extension) == NULL) { + if (ext && strstr(lfile, ext) == NULL) { if (strstr(lfile, DAEMON_NAME) == NULL) { - rc = asprintf(&lfile, "%s%s", lp_logfile(), - extension?extension:""); + rc = asprintf(&lfile, "%s%s", + lp_logfile(), ext?ext:""); + } else { + rc = asprintf(&lfile, "%s.%d", + lp_logfile(), child_id); } - } else if (child_id) { - rc = asprintf(&lfile, "%s.%d", lfile, child_id); } + } - if (rc > 0) { - lp_set_logfile(lfile); - SAFE_FREE(lfile); - } + if (rc > 0) { + lp_set_logfile(lfile); + SAFE_FREE(lfile); } - SAFE_FREE(extension); + SAFE_FREE(ext); reopen_logs(); } @@ -545,6 +542,7 @@ static void spoolss_handle_client(struct tevent_req *req) /* ==== Main Process Functions ==== */ extern pid_t background_lpq_updater_pid; +static char *bq_logfile; static void check_updater_child(void) { @@ -559,7 +557,8 @@ static void check_updater_child(void) if (pid > 0) { DEBUG(2, ("The background queue child died... Restarting!\n")); pid = start_background_queue(server_event_context(), - server_messaging_context()); + server_messaging_context(), + bq_logfile); background_lpq_updater_pid = pid; } } @@ -710,6 +709,23 @@ static void print_queue_forward(struct messaging_context *msg, MSG_PRINTER_UPDATE, data->data, data->length); } +char *get_bq_logfile(void) +{ + char *lfile = lp_logfile(); + int rc; + + if (lfile == NULL || lfile[0] == '\0') { + rc = asprintf(&lfile, "%s/log.%s.bq", + get_dyn_LOGFILEBASE(), DAEMON_NAME); + } else { + rc = asprintf(&lfile, "%s.bq", lp_logfile()); + } + if (rc == -1) { + lfile = NULL; + } + return lfile; +} + pid_t start_spoolssd(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx) { @@ -754,7 +770,8 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx, pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers); /* always start the backgroundqueue listner in spoolssd */ - pid = start_background_queue(ev_ctx, msg_ctx); + bq_logfile = get_bq_logfile(); + pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile); if (pid > 0) { background_lpq_updater_pid = pid; } |