s3-printing: Rework how the background process is started
authorSimo Sorce <idra@samba.org>
Wed, 3 Aug 2011 21:04:50 +0000 (17:04 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:04 +0000 (18:14 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
source3/printing/printing.c
source3/printing/queue_process.c
source3/printing/queue_process.h
source3/printing/spoolssd.c
source3/smbd/globals.c
source3/smbd/globals.h

index ac9e76809290fe9f887b9e88de4ef0e6ba220faf..019fc65c23a8c7689caac0d73d2e29ff9a421b59 100644 (file)
@@ -1609,6 +1609,8 @@ void print_queue_receive(struct messaging_context *msg,
 update the internal database from the system print queue for a queue
 ****************************************************************************/
 
+extern pid_t background_lpq_updater_pid;
+
 static void print_queue_update(struct messaging_context *msg_ctx,
                               int snum, bool force)
 {
index 291a47fcda414264aaa12c6a0f4df16540e8f818..2b15c3640487a771013410916d71147ae164eaf2 100644 (file)
@@ -156,15 +156,14 @@ static void printing_pause_fd_handler(struct tevent_context *ev,
        exit_server_cleanly(NULL);
 }
 
-
-pid_t background_lpq_updater_pid = -1;
-
 /****************************************************************************
 main thread of the background lpq updater
 ****************************************************************************/
-static void start_background_queue(struct tevent_context *ev,
-                                  struct messaging_context *msg_ctx)
+pid_t start_background_queue(struct tevent_context *ev,
+                            struct messaging_context *msg_ctx)
 {
+       pid_t pid;
+
        /* Use local variables for this as we don't
         * need to save the parent side of this, just
         * ensure it closes when the process exits.
@@ -178,14 +177,14 @@ static void start_background_queue(struct tevent_context *ev,
                exit(1);
        }
 
-       background_lpq_updater_pid = sys_fork();
+       pid = sys_fork();
 
-       if (background_lpq_updater_pid == -1) {
+       if (pid == -1) {
                DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
                exit(1);
        }
 
-       if(background_lpq_updater_pid == 0) {
+       if (pid == 0) {
                struct tevent_fd *fde;
                int ret;
                NTSTATUS status;
@@ -206,6 +205,10 @@ static void start_background_queue(struct tevent_context *ev,
                bq_setup_sig_term_handler();
                bq_setup_sig_hup_handler(ev, msg_ctx);
 
+               if (!pcap_cache_loaded()) {
+                       pcap_cache_reload(ev, msg_ctx, &reload_printers);
+               }
+
                if (!printing_subsystem_queue_tasks(ev, msg_ctx)) {
                        exit(1);
                }
@@ -242,39 +245,48 @@ static void start_background_queue(struct tevent_context *ev,
        }
 
        close(pause_pipe[1]);
-}
 
-static bool use_background_queue;
+       return pid;
+}
 
 /* Run before the parent forks */
 bool printing_subsystem_init(struct tevent_context *ev_ctx,
                             struct messaging_context *msg_ctx,
                             bool background_queue)
 {
-       bool ret = true;
-
-       use_background_queue = background_queue;
+       pid_t pid = -1;
 
        if (!print_backend_init(msg_ctx)) {
                return false;
        }
 
-       /* Publish nt printers, this requires a working winreg pipe */
-       pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
-
        if (background_queue) {
-               start_background_queue(ev_ctx, msg_ctx);
+
+               pid = start_background_queue(ev_ctx, msg_ctx);
+
        } else {
+               bool ret;
+
                ret = printing_subsystem_queue_tasks(ev_ctx, msg_ctx);
+
+               /* Publish nt printers, this requires a working winreg pipe */
+               pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
+
+               return ret;
        }
 
-       return ret;
+       if (pid == -1) {
+               return false;
+       }
+       background_lpq_updater_pid = pid;
+
+       return true;
 }
 
 void printing_subsystem_update(struct tevent_context *ev_ctx,
                               struct messaging_context *msg_ctx)
 {
-       if (use_background_queue) return;
+       if (background_lpq_updater_pid != -1) return;
 
        pcap_cache_reload(ev_ctx, msg_ctx, &reload_pcap_change_notify);
 }
index 41305d85ab130a99a8f19ad34e199d001bc4e4da..9401e00fb0a0e338d8ef481a930df41fc80cd412 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-extern pid_t background_lpq_updater_pid;
-
 bool printing_subsystem_init(struct tevent_context *ev_ctx,
                             struct messaging_context *msg_ctx,
                             bool background_queue);
 void printing_subsystem_update(struct tevent_context *ev_ctx,
                               struct messaging_context *msg_ctx);
+pid_t start_background_queue(struct tevent_context *ev,
+                            struct messaging_context *msg);
index 27704dab3ca588ef7983dfd79058f3343b66aac0..13f300d19a8e9c972663adb6b2f8c3dcdeb35c63 100644 (file)
@@ -23,6 +23,7 @@
 #include "messages.h"
 #include "include/printing.h"
 #include "printing/nt_printing_migrate_internal.h"
+#include "printing/pcap.h"
 #include "ntdomain.h"
 #include "librpc/gen_ndr/srv_winreg.h"
 #include "librpc/gen_ndr/srv_spoolss.h"
@@ -695,6 +696,9 @@ void start_spoolssd(struct tevent_context *ev_ctx,
        spoolss_reopen_logs();
        spoolss_prefork_config();
 
+       /* Publish nt printers, this requires a working winreg pipe */
+       pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
+
        /* the listening fd must be created before the children are actually
         * forked out. */
        listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME);
index 8cc1a31aecf0dbb3d969d163617536549d85e52b..5cba80fb890d2d082df2ce157b35c6cfa4bb6820 100644 (file)
@@ -60,6 +60,7 @@ bool logged_ioctl_message = false;
 
 time_t last_smb_conf_reload_time = 0;
 time_t last_printer_reload_time = 0;
+pid_t background_lpq_updater_pid = -1;
 
 /****************************************************************************
  structure to hold a linked list of queued messages.
index 26125ce805e78ff85414732a453decbdbff2c70b..b9bd21215cd5b23dd34497f36144ca4d9ca0542b 100644 (file)
@@ -66,6 +66,8 @@ extern int trans_num;
 
 extern time_t last_smb_conf_reload_time;
 extern time_t last_printer_reload_time;
+extern pid_t background_lpq_updater_pid;
+
 /****************************************************************************
  structure to hold a linked list of queued messages.
  for processing.