summaryrefslogtreecommitdiffstats
path: root/source/printing/printing.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/printing/printing.c')
-rw-r--r--source/printing/printing.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/source/printing/printing.c b/source/printing/printing.c
index 2355dd14506..2274e2d5f45 100644
--- a/source/printing/printing.c
+++ b/source/printing/printing.c
@@ -971,7 +971,7 @@ static void check_job_changed(int snum, TDB_DATA data, uint32 jobid)
Update the internal database from the system print queue for a queue.
****************************************************************************/
-static void print_queue_update(int snum)
+static void print_queue_update_internal(int snum)
{
int i, qcount;
print_queue_struct *queue = NULL;
@@ -1151,6 +1151,73 @@ static void print_queue_update(int snum)
}
/****************************************************************************
+this is the receive function of the background lpq updater
+****************************************************************************/
+static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t len)
+{
+ int snum;
+ snum=*((int *)buf);
+ print_queue_update_internal(snum);
+}
+
+static pid_t background_lpq_updater_pid = -1;
+
+/****************************************************************************
+main thread of the background lpq updater
+****************************************************************************/
+void start_background_queue(void)
+{
+ DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));
+ background_lpq_updater_pid = sys_fork();
+
+ if (background_lpq_updater_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) {
+ /* Child. */
+ DEBUG(5,("start_background_queue: background LPQ thread started\n"));
+
+ claim_connection( NULL, "smbd lpq backend", 0, False,
+ FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINTING );
+
+ if (!locking_init(0)) {
+ exit(1);
+ }
+
+ if (!print_backend_init()) {
+ exit(1);
+ }
+
+ message_register(MSG_PRINTER_UPDATE, print_queue_receive);
+
+ DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
+ while (1) {
+ pause();
+ DEBUG(10,("start_background_queue: background LPQ thread got a message\n"));
+ message_dispatch();
+ }
+ }
+}
+
+/****************************************************************************
+update the internal database from the system print queue for a queue
+****************************************************************************/
+static void print_queue_update(int snum)
+{
+ /*
+ * Make sure that the backgroup queueu process exists.
+ * Otherwise just do the update ourselves
+ */
+
+ if ( background_lpq_updater_pid != -1 )
+ message_send_pid(background_lpq_updater_pid, MSG_PRINTER_UPDATE, &snum, sizeof(snum), False);
+ else
+ print_queue_update_internal( snum );
+}
+
+/****************************************************************************
Create/Update an entry in the print tdb that will allow us to send notify
updates only to interested smbd's.
****************************************************************************/