printing: move pcap change notifier to bg process
authorDavid Disseldorp <ddiss@samba.org>
Thu, 14 Feb 2013 13:42:21 +0000 (14:42 +0100)
committerKarolin Seeger <kseeger@samba.org>
Fri, 26 Apr 2013 07:25:02 +0000 (09:25 +0200)
The background print queue process is responsible for printcap cache
updates, and should be the only process to send notifications.
(cherry picked from commit 23ac828ba93e2ffc60ced19656af9609dcc1b2ab)

source3/printing/printing.c
source3/smbd/process.c
source3/smbd/proto.h
source3/smbd/server_reload.c

index 376fc7c2b08a11365c790b152a96d9a8204ba234..21f318c764babe1590c7277d4fe732a762c3fbd0 100644 (file)
@@ -1656,6 +1656,24 @@ static void add_child_pid(pid_t pid)
         num_children += 1;
 }
 
+/****************************************************************************
+ Notify smbds of new printcap data
+**************************************************************************/
+static void reload_pcap_change_notify(struct tevent_context *ev,
+                                     struct messaging_context *msg_ctx)
+{
+       /*
+        * Reload the printers first in the background process so that
+        * newly added printers get default values created in the registry.
+        *
+        * This will block the process for some time (~1 sec per printer), but
+        * it doesn't block smbd's servering clients.
+        */
+       reload_printers(ev, msg_ctx);
+
+       message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);
+}
+
 static bool printer_housekeeping_fn(const struct timeval *now,
                                    void *private_data)
 {
@@ -1678,6 +1696,30 @@ static bool printer_housekeeping_fn(const struct timeval *now,
        return true;
 }
 
+static void printing_sig_term_handler(struct tevent_context *ev,
+                                     struct tevent_signal *se,
+                                     int signum,
+                                     int count,
+                                     void *siginfo,
+                                     void *private_data)
+{
+       exit_server_cleanly("termination signal");
+}
+
+static void printing_sig_hup_handler(struct tevent_context *ev,
+                                 struct tevent_signal *se,
+                                 int signum,
+                                 int count,
+                                 void *siginfo,
+                                 void *private_data)
+{
+       struct messaging_context *msg_ctx = talloc_get_type_abort(
+               private_data, struct messaging_context);
+
+       DEBUG(1,("Reloading printers after SIGHUP\n"));
+       reload_pcap_change_notify(ev, msg_ctx);
+}
+
 static pid_t background_lpq_updater_pid = -1;
 
 /****************************************************************************
@@ -1713,6 +1755,7 @@ void start_background_queue(struct tevent_context *ev,
                struct tevent_fd *fde;
                int ret;
                NTSTATUS status;
+               struct tevent_signal *se;
 
                /* Child. */
                DEBUG(5,("start_background_queue: background LPQ thread started\n"));
@@ -1727,8 +1770,18 @@ void start_background_queue(struct tevent_context *ev,
                        smb_panic("reinit_after_fork() failed");
                }
 
-               smbd_setup_sig_term_handler();
-               smbd_setup_sig_hup_handler(ev, msg_ctx);
+               se = tevent_add_signal(ev, ev, SIGTERM, 0,
+                                      printing_sig_term_handler,
+                                      NULL);
+               if (se == NULL) {
+                       smb_panic("failed to setup SIGTERM handler");
+               }
+               se = tevent_add_signal(ev, ev, SIGHUP, 0,
+                                      printing_sig_hup_handler,
+                                      msg_ctx);
+               if (se == NULL) {
+                       smb_panic("failed to setup SIGHUP handler");
+               }
 
                if (!serverid_register(procid_self(),
                                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD
index 358d0515ae702e6bd1f2ff30f79b09187d36fbf1..b93b9599fb545808d3d6e96f4991a6ccb8e461c3 100644 (file)
@@ -957,9 +957,6 @@ static void smbd_sig_hup_handler(struct tevent_context *ev,
        change_to_root_user();
        DEBUG(1,("Reloading services after SIGHUP\n"));
        reload_services(msg_ctx, smbd_server_conn->sock, False);
-       if (am_parent) {
-               pcap_cache_reload(ev, msg_ctx, &reload_pcap_change_notify);
-       }
 }
 
 void smbd_setup_sig_hup_handler(struct tevent_context *ev,
index d6f751175c7311db173237fb8ef7001ffac8cdfc..2baa58da981d6cea400ca9b3508dd2d26bd9f778 100644 (file)
@@ -770,8 +770,6 @@ NTSTATUS make_default_filesystem_acl(TALLOC_CTX *ctx,
 /* The following definitions come from smbd/process.c  */
 
 void smbd_setup_sig_term_handler(void);
-void smbd_setup_sig_hup_handler(struct tevent_context *ev,
-                               struct messaging_context *msg_ctx);
 bool srv_send_smb(struct smbd_server_connection *sconn, char *buffer,
                  bool no_signing, uint32_t seqnum,
                  bool do_encrypt,
@@ -982,8 +980,6 @@ void reload_printers(struct tevent_context *ev,
                     struct messaging_context *msg_ctx);
 bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
                     bool test);
-void reload_pcap_change_notify(struct tevent_context *ev,
-                              struct messaging_context *msg_ctx);
 void exit_server(const char *const explanation);
 void exit_server_cleanly(const char *const explanation);
 void exit_server_fault(void);
index bda5d08a6375ea42fc2f9f533d8efc3480e0cd0e..f4c15f8272c1265e62ab5c3d9eb5ffc1160fca2f 100644 (file)
@@ -160,21 +160,3 @@ bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
 
        return(ret);
 }
-
-/****************************************************************************
- Notify smbds of new printcap data
-**************************************************************************/
-void reload_pcap_change_notify(struct tevent_context *ev,
-                              struct messaging_context *msg_ctx)
-{
-       /*
-        * Reload the printers first in the background process so that
-        * newly added printers get default values created in the registry.
-        *
-        * This will block the process for some time (~1 sec per printer), but
-        * it doesn't block smbd's servering clients.
-        */
-       reload_printers(ev, msg_ctx);
-
-       message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);
-}