summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/messages.h1
-rw-r--r--source3/printing/printing.c52
-rw-r--r--source3/smbd/server.c2
3 files changed, 53 insertions, 2 deletions
diff --git a/source3/include/messages.h b/source3/include/messages.h
index cc10f3b90b..dfbc486211 100644
--- a/source3/include/messages.h
+++ b/source3/include/messages.h
@@ -37,6 +37,7 @@
/* rpc messages */
#define MSG_PRINTER_NOTIFY 2001
+#define MSG_PRINTER_UPDATE 2002
/* smbd messages */
#define MSG_SMB_CONF_UPDATED 3001
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 9135cb2d5e..db67585332 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -311,10 +311,10 @@ static void set_updating_pid(fstring printer_name, BOOL delete)
}
/****************************************************************************
-update the internal database from the system print queue for a queue
+update the internal database from the system print queue for a queue in the background
****************************************************************************/
-static void print_queue_update(int snum)
+static void print_queue_update_background(int snum)
{
int i, qcount;
print_queue_struct *queue = NULL;
@@ -468,6 +468,54 @@ 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_background(snum);
+}
+
+/****************************************************************************
+main thread of the background lpq updater
+****************************************************************************/
+void start_background_queue(void)
+{
+ DEBUG(3,("Starting background LPQ thread\n"));
+ if(sys_fork()==0) {
+ DEBUG(5,("background LPQ thread started\n"));
+
+ claim_connection(NULL,"smbd lpq backend",MAXSTATUS,False);
+
+ if (!locking_init(0)) {
+ exit(1);
+ }
+
+ if (!print_backend_init()) {
+ exit(1);
+ }
+
+ message_register(MSG_PRINTER_UPDATE, print_queue_receive);
+
+ DEBUG(5,("background LPQ thread waiting for messages\n"));
+ while (1) {
+ pause();
+ DEBUG(10,("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)
+{
+ message_send_all(conn_tdb_ctx(), MSG_PRINTER_UPDATE, &snum, sizeof(snum), False);
+}
+
+/****************************************************************************
check if a jobid is valid. It is valid if it exists in the database
****************************************************************************/
BOOL print_job_exists(int jobid)
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index f707a61376..4599cef41f 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -791,6 +791,8 @@ static void usage(char *pname)
/* Setup the main smbd so that we can get messages. */
claim_connection(NULL,"",MAXSTATUS,True);
+ start_background_queue();
+
if (!open_sockets(is_daemon,port))
exit(1);