s3-printing: make sure to block SIGHUP ...
authorSimo Sorce <idra@samba.org>
Mon, 8 Aug 2011 14:08:46 +0000 (10:08 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:05 +0000 (18:14 +0200)
... until we are ready to handle it.

Also make us ready as early as possible in spoolssd.

Signed-off-by: Andreas Schneider <asn@samba.org>
source3/printing/queue_process.c
source3/printing/spoolssd.c

index a56baaf6b772cae789b38dcdc3a3453676cde6fb..1b7b4f85790ac7524db31394791b94db50ecfa9b 100644 (file)
@@ -191,8 +191,24 @@ pid_t start_background_queue(struct tevent_context *ev,
                exit(1);
        }
 
+       /*
+        * Block signals before forking child as it will have to
+        * set its own handlers. Child will re-enable SIGHUP as
+        * soon as the handlers are set up.
+        */
+       BlockSignals(true, SIGTERM);
+       BlockSignals(true, SIGHUP);
+
        pid = sys_fork();
 
+       /* parent or error */
+       if (pid != 0) {
+               /* Re-enable SIGHUP before returnig */
+               BlockSignals(false, SIGTERM);
+               BlockSignals(false, SIGHUP);
+               return pid;
+       }
+
        if (pid == -1) {
                DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
                exit(1);
@@ -220,6 +236,9 @@ pid_t start_background_queue(struct tevent_context *ev,
                bq_setup_sig_term_handler();
                bq_setup_sig_hup_handler(ev, msg_ctx);
 
+               BlockSignals(false, SIGTERM);
+               BlockSignals(false, SIGHUP);
+
                if (!pcap_cache_loaded()) {
                        pcap_cache_reload(ev, msg_ctx, &reload_printers);
                }
index 774f67da1bde4e6f9faeabc5f2a52a405e17acc2..4379179f02cfc78fb51cb9ad8c61bbecd2ff00e3 100644 (file)
@@ -713,14 +713,27 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
 
        DEBUG(1, ("Forking SPOOLSS Daemon\n"));
 
+       /*
+        * Block signals before forking child as it will have to
+        * set its own handlers. Child will re-enable SIGHUP as
+        * soon as the handlers are set up.
+        */
+       BlockSignals(true, SIGTERM);
+       BlockSignals(true, SIGHUP);
+
        pid = sys_fork();
 
        if (pid == -1) {
                DEBUG(0, ("Failed to fork SPOOLSS [%s]\n",
                           strerror(errno)));
        }
+
+       /* parent or error */
        if (pid != 0) {
-               /* parent or error */
+
+               /* Re-enable SIGHUP before returnig */
+               BlockSignals(false, SIGTERM);
+               BlockSignals(false, SIGHUP);
                return pid;
        }
 
@@ -738,6 +751,12 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
        spoolss_reopen_logs(0);
        spoolss_prefork_config();
 
+       spoolss_setup_sig_term_handler(ev_ctx);
+       spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx);
+
+       BlockSignals(false, SIGTERM);
+       BlockSignals(false, SIGHUP);
+
        /* Publish nt printers, this requires a working winreg pipe */
        pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
 
@@ -771,9 +790,6 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
                                 &spoolss_children_main, NULL,
                                 &spoolss_pool);
 
-       spoolss_setup_sig_term_handler(ev_ctx);
-       spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx);
-
        if (!serverid_register(procid_self(),
                                FLAG_MSG_GENERAL|FLAG_MSG_SMBD
                                |FLAG_MSG_PRINT_GENERAL)) {