s3-printing: Allow bq process to have own logfile
authorSimo Sorce <idra@samba.org>
Fri, 5 Aug 2011 19:14:26 +0000 (15:14 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:05 +0000 (18:14 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
source3/printing/queue_process.c
source3/printing/queue_process.h
source3/printing/spoolssd.c

index 82fd70d36d6222517de2b553d118679f158431cb..a56baaf6b772cae789b38dcdc3a3453676cde6fb 100644 (file)
@@ -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;
index 5f282c44629921daf11b5c59765283c5b2cdfed6..b76936495274de74ce61fd40045427f34c62554b 100644 (file)
@@ -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);
index 79731ee9480075dcee301beca46d420923a87c13..038d3dbc1240d88096cd09e4c89f59435cdd89e9 100644 (file)
@@ -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;
        }