From 2ce6b4a78efa548720566bf84e5f2b81337bffd7 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 14 Feb 2013 17:02:08 +0100 Subject: [PATCH] printing: add sighup and conf change handlers The background printing process is now responsible for all printcap cache updates, which should be done on SIGHUP and configuration change. (cherry picked from commit f4af7c4d4cafe15c437742d450c7753a8b6d8422) --- source3/printing/printing.c | 17 ++++++++++++++- source3/smbd/process.c | 50 ------------------------------------------ source3/smbd/proto.h | 1 - source3/smbd/server.c | 53 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 53 deletions(-) diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 21f318c764b..780afcfedb9 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -1717,9 +1717,22 @@ static void printing_sig_hup_handler(struct tevent_context *ev, private_data, struct messaging_context); DEBUG(1,("Reloading printers after SIGHUP\n")); - reload_pcap_change_notify(ev, msg_ctx); + pcap_cache_reload(ev, msg_ctx, + &reload_pcap_change_notify); } +static void printing_conf_updated(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) +{ + DEBUG(5,("Reloading printers after conf change\n")); + pcap_cache_reload(messaging_event_context(msg), msg, + &reload_pcap_change_notify); +} + + static pid_t background_lpq_updater_pid = -1; /**************************************************************************** @@ -1795,6 +1808,8 @@ void start_background_queue(struct tevent_context *ev, messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE, print_queue_receive); + messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED, + printing_conf_updated); fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ, printing_pause_fd_handler, diff --git a/source3/smbd/process.c b/source3/smbd/process.c index b93b9599fb5..f43005dda3a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -921,56 +921,6 @@ struct idle_event *event_add_idle(struct event_context *event_ctx, return result; } -static void smbd_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"); -} - -void smbd_setup_sig_term_handler(void) -{ - struct tevent_signal *se; - - se = tevent_add_signal(smbd_event_context(), - smbd_event_context(), - SIGTERM, 0, - smbd_sig_term_handler, - NULL); - if (!se) { - exit_server("failed to setup SIGTERM handler"); - } -} - -static void smbd_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); - change_to_root_user(); - DEBUG(1,("Reloading services after SIGHUP\n")); - reload_services(msg_ctx, smbd_server_conn->sock, False); -} - -void smbd_setup_sig_hup_handler(struct tevent_context *ev, - struct messaging_context *msg_ctx) -{ - struct tevent_signal *se; - - se = tevent_add_signal(ev, ev, SIGHUP, 0, smbd_sig_hup_handler, - msg_ctx); - if (!se) { - exit_server("failed to setup SIGHUP handler"); - } -} - static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *conn) { int timeout; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 2baa58da981..3b0f8172648 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -769,7 +769,6 @@ NTSTATUS make_default_filesystem_acl(TALLOC_CTX *ctx, /* The following definitions come from smbd/process.c */ -void smbd_setup_sig_term_handler(void); bool srv_send_smb(struct smbd_server_connection *sconn, char *buffer, bool no_signing, uint32_t seqnum, bool do_encrypt, diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 4a4a006c0c1..a08131f9a7f 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -108,7 +108,7 @@ static void smb_conf_updated(struct messaging_context *msg, "updated. Reloading.\n")); change_to_root_user(); reload_services(msg, smbd_server_conn->sock, False); - reload_printers(ev_ctx, msg); + /* printer reload triggered by background printing process */ } /******************************************************************* @@ -129,6 +129,57 @@ static void smb_pcap_updated(struct messaging_context *msg, reload_printers(ev_ctx, msg); } +static void smbd_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 smbd_setup_sig_term_handler(void) +{ + struct tevent_signal *se; + + se = tevent_add_signal(smbd_event_context(), + smbd_event_context(), + SIGTERM, 0, + smbd_sig_term_handler, + NULL); + if (!se) { + exit_server("failed to setup SIGTERM handler"); + } +} + +static void smbd_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); + change_to_root_user(); + DEBUG(1,("Reloading services after SIGHUP\n")); + reload_services(msg_ctx, smbd_server_conn->sock, false); +} + +static void smbd_setup_sig_hup_handler(struct tevent_context *ev, + struct messaging_context *msg_ctx) +{ + struct tevent_signal *se; + + se = tevent_add_signal(ev, ev, SIGHUP, 0, smbd_sig_hup_handler, + msg_ctx); + if (!se) { + exit_server("failed to setup SIGHUP handler"); + } +} + + /******************************************************************* Delete a statcache entry. ********************************************************************/ -- 2.11.4.GIT