s3:printing/spoolssd: avoid using server_messaging_context()
[mat/samba.git] / source3 / printing / spoolssd.c
index b833529f8f92f6a4583b5898997760ac2edd5378..9a5d1b0fef2108bc9b00c22fbdc0c3958e0d7e59 100644 (file)
@@ -103,7 +103,7 @@ static void update_conf(struct tevent_context *ev,
 {
        change_to_root_user();
        lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
-       reload_printers(ev, msg);
+       load_printers(ev, msg);
 
        spoolss_reopen_logs(spoolss_child_id);
        if (spoolss_child_id == 0) {
@@ -131,7 +131,7 @@ static void update_pcap(struct tevent_context *ev_ctx,
                        struct messaging_context *msg_ctx)
 {
        change_to_root_user();
-       reload_printers(ev_ctx, msg_ctx);
+       delete_and_reload_printers(ev_ctx, msg_ctx);
 }
 
 static void pcap_updated(struct messaging_context *msg,
@@ -224,11 +224,6 @@ static bool spoolss_shutdown_cb(void *ptr)
 
 /* Children */
 
-struct spoolss_chld_sig_hup_ctx {
-       struct messaging_context *msg_ctx;
-       struct pf_worker_data *pf;
-};
-
 static void spoolss_chld_sig_hup_handler(struct tevent_context *ev,
                                         struct tevent_signal *se,
                                         int signum,
@@ -236,19 +231,13 @@ static void spoolss_chld_sig_hup_handler(struct tevent_context *ev,
                                         void *siginfo,
                                         void *pvt)
 {
-       struct spoolss_chld_sig_hup_ctx *shc;
-
-       shc = talloc_get_type_abort(pvt, struct spoolss_chld_sig_hup_ctx);
+       struct messaging_context *msg_ctx;
 
-       /* avoid wasting CPU cycles if we are going to exit soon anyways */
-       if (shc->pf != NULL &&
-           shc->pf->cmds == PF_SRV_MSG_EXIT) {
-               return;
-       }
+       msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
 
        change_to_root_user();
        DEBUG(1,("Reloading printers after SIGHUP\n"));
-       reload_printers(ev, shc->msg_ctx);
+       load_printers(ev, msg_ctx);
        spoolss_reopen_logs(spoolss_child_id);
 }
 
@@ -256,22 +245,13 @@ static bool spoolss_setup_chld_hup_handler(struct tevent_context *ev_ctx,
                                           struct messaging_context *msg_ctx,
                                           struct pf_worker_data *pf)
 {
-       struct spoolss_chld_sig_hup_ctx *shc;
        struct tevent_signal *se;
 
-       shc = talloc(ev_ctx, struct spoolss_chld_sig_hup_ctx);
-       if (!shc) {
-               DEBUG(1, ("failed to setup SIGHUP handler"));
-               return false;
-       }
-       shc->pf = pf;
-       shc->msg_ctx = msg_ctx;
-
        se = tevent_add_signal(ev_ctx,
                               ev_ctx,
                               SIGHUP, 0,
                               spoolss_chld_sig_hup_handler,
-                              shc);
+                              msg_ctx);
        if (!se) {
                DEBUG(1, ("failed to setup SIGHUP handler"));
                return false;
@@ -280,16 +260,32 @@ static bool spoolss_setup_chld_hup_handler(struct tevent_context *ev_ctx,
        return true;
 }
 
+static void parent_ping(struct messaging_context *msg_ctx,
+                       void *private_data,
+                       uint32_t msg_type,
+                       struct server_id server_id,
+                       DATA_BLOB *data)
+{
+
+       /* The fact we received this message is enough to let make the event
+        * loop if it was idle. spoolss_children_main will cycle through
+        * spoolss_next_client at least once. That function will take whatever
+        * action is necessary */
+
+       DEBUG(10, ("Got message that the parent changed status.\n"));
+       return;
+}
+
 static bool spoolss_child_init(struct tevent_context *ev_ctx,
                               int child_id, struct pf_worker_data *pf)
 {
        NTSTATUS status;
        struct rpc_srv_callbacks spoolss_cb;
-       struct messaging_context *msg_ctx = server_messaging_context();
+       struct messaging_context *msg_ctx = messaging_init(NULL, ev_ctx);
        bool ok;
 
        status = reinit_after_fork(msg_ctx, ev_ctx,
-                                  procid_self(), true);
+                                  true);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                smb_panic("reinit_after_fork() failed");
@@ -317,6 +313,8 @@ static bool spoolss_child_init(struct tevent_context *ev_ctx,
                           MSG_SMB_CONF_UPDATED, smb_conf_updated);
        messaging_register(msg_ctx, ev_ctx, MSG_PRINTER_PCAP,
                           pcap_updated);
+       messaging_register(msg_ctx, ev_ctx,
+                          MSG_PREFORK_PARENT_EVENT, parent_ping);
 
        /* As soon as messaging is up check if pcap has been loaded already.
         * If so then we probably missed a message and should load_printers()
@@ -491,7 +489,8 @@ static void spoolss_handle_client(struct tevent_req *req)
 extern pid_t background_lpq_updater_pid;
 static char *bq_logfile;
 
-static void check_updater_child(void)
+static void check_updater_child(struct tevent_context *ev_ctx,
+                               struct messaging_context *msg_ctx)
 {
        int status;
        pid_t pid;
@@ -503,9 +502,7 @@ static void check_updater_child(void)
        pid = sys_waitpid(background_lpq_updater_pid, &status, WNOHANG);
        if (pid > 0) {
                DEBUG(2, ("The background queue child died... Restarting!\n"));
-               pid = start_background_queue(server_event_context(),
-                                            server_messaging_context(),
-                                            bq_logfile);
+               pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile);
                background_lpq_updater_pid = pid;
        }
 }
@@ -545,7 +542,7 @@ static void spoolssd_sigchld_handler(struct tevent_context *ev_ctx,
        pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
 
        /* also check if the updater child is alive and well */
-       check_updater_child();
+       check_updater_child(ev_ctx, msg_ctx);
 }
 
 static bool spoolssd_setup_children_monitor(struct tevent_context *ev_ctx,
@@ -668,7 +665,7 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
 
        status = reinit_after_fork(msg_ctx,
                                   ev_ctx,
-                                  procid_self(), true);
+                                  true);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                smb_panic("reinit_after_fork() failed");