From 0b7efa6182388eaeeb31bb9a29a244eb150ff852 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Tue, 12 Feb 2013 18:57:53 +0100 Subject: [PATCH] smbd: fix cups printcap cache updates on startup On startup the parent smbd process currently calls pcap_cache_reload(), which is done immediately before the background queue process is forked. pcap_cache_reload() is asynchronous with cups, in that it forks a separate process to obtain the printer listing. The cache_fd_event print_cups.c global variable is used to track when a cups printer listing is in progress. cache_fd_event is set when the background queue process is forked, due to smbd's pcap_cache_reload() call immediately prior. As a result, the background queue process assumes an existing pcap_cache_reload() call is indefinitely outstanding, causing the printcap cache to remain stale thereafter. (cherry picked from commit d7286bb6520ebe03355e98e3311e1d79e2746791) --- source3/printing/printing.c | 5 +++++ source3/smbd/server.c | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/source3/printing/printing.c b/source3/printing/printing.c index a5b36c725d0..376fc7c2b08 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -1751,6 +1751,11 @@ void start_background_queue(struct tevent_context *ev, smb_panic("tevent_add_fd() failed for pause_pipe"); } + /* reload on startup to ensure parent smbd is refreshed */ + pcap_cache_reload(server_event_context(), + smbd_messaging_context(), + &reload_pcap_change_notify); + if (!(event_add_idle(ev, NULL, timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0), "printer_housekeeping", diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 4b6114a7f9e..4a4a006c0c1 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -108,10 +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); - if (am_parent) { - pcap_cache_reload(ev_ctx, msg, - &reload_pcap_change_notify); - } + reload_printers(ev_ctx, msg); } /******************************************************************* @@ -772,8 +769,6 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent, messaging_register(msg_ctx, NULL, MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete); messaging_register(msg_ctx, NULL, MSG_DEBUG, smbd_msg_debug); - messaging_register(msg_ctx, server_event_context(), MSG_PRINTER_PCAP, - smb_pcap_updated); brl_register_msgs(msg_ctx); msg_idmap_register_msgs(msg_ctx); @@ -1234,10 +1229,6 @@ extern void build_options(bool screen); if (!print_backend_init(smbd_messaging_context())) exit(1); - /* Publish nt printers, this requires a working winreg pipe */ - pcap_cache_reload(server_event_context(), smbd_messaging_context(), - &reload_printers); - /* only start the background queue daemon if we are running as a daemon -- bad things will happen if smbd is launched via inetd and we fork a copy of @@ -1245,8 +1236,19 @@ extern void build_options(bool screen); if (is_daemon && !interactive && lp_parm_bool(-1, "smbd", "backgroundqueue", true)) { - start_background_queue(smbd_event_context(), - smbd_messaging_context()); + /* background queue is responsible for printcap cache updates */ + messaging_register(smbd_server_conn->msg_ctx, + smbd_event_context(), + MSG_PRINTER_PCAP, smb_pcap_updated); + start_background_queue(server_event_context(), + smbd_server_conn->msg_ctx); + } else { + DEBUG(3, ("running without background printer process, dynamic " + "printer updates disabled\n")); + /* Publish nt printers, this requires a working winreg pipe */ + pcap_cache_reload(server_event_context(), + smbd_messaging_context(), + &reload_printers); } if (is_daemon && !_lp_disable_spoolss()) { -- 2.11.4.GIT