From 23ac828ba93e2ffc60ced19656af9609dcc1b2ab Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 14 Feb 2013 14:42:21 +0100 Subject: [PATCH] printing: move pcap change notifier to bg process The background print queue process is responsible for printcap cache updates, and should be the only process to send notifications. --- source3/printing/printing.c | 57 ++++++++++++++++++++++++++++++++++++++++++-- source3/smbd/process.c | 3 --- source3/smbd/proto.h | 4 ---- source3/smbd/server_reload.c | 18 -------------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 376fc7c2b08..21f318c764b 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -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 diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 358d0515ae7..b93b9599fb5 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -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, diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index d6f751175c7..2baa58da981 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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); diff --git a/source3/smbd/server_reload.c b/source3/smbd/server_reload.c index bda5d08a637..f4c15f8272c 100644 --- a/source3/smbd/server_reload.c +++ b/source3/smbd/server_reload.c @@ -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); -} -- 2.11.4.GIT