summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2011-08-03 17:04:50 -0400
committerAndreas Schneider <asn@samba.org>2011-08-10 18:14:04 +0200
commit9ce64166731dcacf7e2774380fe58ec780568d2e (patch)
tree9420d413d4e5bfb208efcb93060c1c185d0f8328 /source3/printing
parent0a910c93472e1e4aff120219e09866d4a20ec2b2 (diff)
downloadsamba-9ce64166731dcacf7e2774380fe58ec780568d2e.tar.gz
samba-9ce64166731dcacf7e2774380fe58ec780568d2e.tar.bz2
samba-9ce64166731dcacf7e2774380fe58ec780568d2e.zip
s3-printing: Rework how the background process is started
Signed-off-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/printing.c2
-rw-r--r--source3/printing/queue_process.c50
-rw-r--r--source3/printing/queue_process.h4
-rw-r--r--source3/printing/spoolssd.c4
4 files changed, 39 insertions, 21 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index ac9e768092..019fc65c23 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -1609,6 +1609,8 @@ void print_queue_receive(struct messaging_context *msg,
update the internal database from the system print queue for a queue
****************************************************************************/
+extern pid_t background_lpq_updater_pid;
+
static void print_queue_update(struct messaging_context *msg_ctx,
int snum, bool force)
{
diff --git a/source3/printing/queue_process.c b/source3/printing/queue_process.c
index 291a47fcda..2b15c36404 100644
--- a/source3/printing/queue_process.c
+++ b/source3/printing/queue_process.c
@@ -156,15 +156,14 @@ static void printing_pause_fd_handler(struct tevent_context *ev,
exit_server_cleanly(NULL);
}
-
-pid_t background_lpq_updater_pid = -1;
-
/****************************************************************************
main thread of the background lpq updater
****************************************************************************/
-static void start_background_queue(struct tevent_context *ev,
- struct messaging_context *msg_ctx)
+pid_t start_background_queue(struct tevent_context *ev,
+ struct messaging_context *msg_ctx)
{
+ pid_t pid;
+
/* Use local variables for this as we don't
* need to save the parent side of this, just
* ensure it closes when the process exits.
@@ -178,14 +177,14 @@ static void start_background_queue(struct tevent_context *ev,
exit(1);
}
- background_lpq_updater_pid = sys_fork();
+ pid = sys_fork();
- if (background_lpq_updater_pid == -1) {
+ if (pid == -1) {
DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
exit(1);
}
- if(background_lpq_updater_pid == 0) {
+ if (pid == 0) {
struct tevent_fd *fde;
int ret;
NTSTATUS status;
@@ -206,6 +205,10 @@ static void start_background_queue(struct tevent_context *ev,
bq_setup_sig_term_handler();
bq_setup_sig_hup_handler(ev, msg_ctx);
+ if (!pcap_cache_loaded()) {
+ pcap_cache_reload(ev, msg_ctx, &reload_printers);
+ }
+
if (!printing_subsystem_queue_tasks(ev, msg_ctx)) {
exit(1);
}
@@ -242,39 +245,48 @@ static void start_background_queue(struct tevent_context *ev,
}
close(pause_pipe[1]);
-}
-static bool use_background_queue;
+ return pid;
+}
/* Run before the parent forks */
bool printing_subsystem_init(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
bool background_queue)
{
- bool ret = true;
-
- use_background_queue = background_queue;
+ pid_t pid = -1;
if (!print_backend_init(msg_ctx)) {
return false;
}
- /* Publish nt printers, this requires a working winreg pipe */
- pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
-
if (background_queue) {
- start_background_queue(ev_ctx, msg_ctx);
+
+ pid = start_background_queue(ev_ctx, msg_ctx);
+
} else {
+ bool ret;
+
ret = printing_subsystem_queue_tasks(ev_ctx, msg_ctx);
+
+ /* Publish nt printers, this requires a working winreg pipe */
+ pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
+
+ return ret;
}
- return ret;
+ if (pid == -1) {
+ return false;
+ }
+ background_lpq_updater_pid = pid;
+
+ return true;
}
void printing_subsystem_update(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx)
{
- if (use_background_queue) return;
+ if (background_lpq_updater_pid != -1) return;
pcap_cache_reload(ev_ctx, msg_ctx, &reload_pcap_change_notify);
}
diff --git a/source3/printing/queue_process.h b/source3/printing/queue_process.h
index 41305d85ab..9401e00fb0 100644
--- a/source3/printing/queue_process.h
+++ b/source3/printing/queue_process.h
@@ -20,10 +20,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-extern pid_t background_lpq_updater_pid;
-
bool printing_subsystem_init(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
bool background_queue);
void printing_subsystem_update(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx);
+pid_t start_background_queue(struct tevent_context *ev,
+ struct messaging_context *msg);
diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c
index 27704dab3c..13f300d19a 100644
--- a/source3/printing/spoolssd.c
+++ b/source3/printing/spoolssd.c
@@ -23,6 +23,7 @@
#include "messages.h"
#include "include/printing.h"
#include "printing/nt_printing_migrate_internal.h"
+#include "printing/pcap.h"
#include "ntdomain.h"
#include "librpc/gen_ndr/srv_winreg.h"
#include "librpc/gen_ndr/srv_spoolss.h"
@@ -695,6 +696,9 @@ void start_spoolssd(struct tevent_context *ev_ctx,
spoolss_reopen_logs();
spoolss_prefork_config();
+ /* Publish nt printers, this requires a working winreg pipe */
+ pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
+
/* the listening fd must be created before the children are actually
* forked out. */
listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME);