From 2bd3a436fd6ed218bced476b502d24f317511fb2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Nov 2000 00:30:15 +0000 Subject: Fix for updating of print queues changed from a local box. Essentially, this makes sure that the change messages sent to ourselves are handled synchronously w.r.t. other smb packets incoming. Jeremy. (This used to be commit 78a13074455618308d048d1c69f62e660988eb90) --- source3/printing/printing.c | 58 +++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'source3/printing') diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 1eb6c27555..0648715699 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -63,6 +63,8 @@ static pid_t local_pid; #define PRINT_SPOOL_PREFIX "smbprn." #define PRINT_DATABASE_VERSION 2 +static int get_queue_status(int, print_status_struct *); + /**************************************************************************** initialise the printing backend. Called once at startup. Does not survive a fork @@ -315,6 +317,7 @@ static void print_queue_update(int snum) int numlines, i, qcount; print_queue_struct *queue = NULL; print_status_struct status; + print_status_struct old_status; struct printjob *pjob; struct traverse_struct tstruct; fstring keystr, printer_name; @@ -409,13 +412,26 @@ static void print_queue_update(int snum) safe_free(tstruct.queue); - /* store the queue status structure */ - status.qcount = qcount; + /* + * Get the old print status. We will use this to compare the + * number of jobs. If they have changed we need to send a + * "changed" message to the smbds. + */ + + if( qcount != get_queue_status(snum, &old_status)) { + DEBUG(10,("print_queue_update: queue status change %d jobs -> %d jobs for printer %s\n", + old_status.qcount, qcount, printer_name )); + message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False); + } + + /* store the new queue status structure */ slprintf(keystr, sizeof(keystr), "STATUS/%s", printer_name); - data.dptr = (void *)&status; - data.dsize = sizeof(status); key.dptr = keystr; key.dsize = strlen(keystr); + + status.qcount = qcount; + data.dptr = (void *)&status; + data.dsize = sizeof(status); tdb_store(tdb, key, data, TDB_REPLACE); /* Unlock for database update */ @@ -713,31 +729,43 @@ static BOOL print_cache_expired(int snum) } /**************************************************************************** - Determine the number of jobs in a queue. + Get the queue status - do not update if db is out of date. ****************************************************************************/ -static int print_queue_length(int snum) +static int get_queue_status(int snum, print_status_struct *status) { fstring keystr; TDB_DATA data, key; - print_status_struct status; - - /* make sure the database is up to date */ - if (print_cache_expired(snum)) print_queue_update(snum); - /* also fetch the queue status */ - ZERO_STRUCTP(&status); + ZERO_STRUCTP(status); slprintf(keystr, sizeof(keystr), "STATUS/%s", lp_servicename(snum)); key.dptr = keystr; key.dsize = strlen(keystr); data = tdb_fetch(tdb, key); if (data.dptr) { - if (data.dsize == sizeof(status)) { - memcpy(&status, data.dptr, sizeof(status)); + if (data.dsize == sizeof(print_status_struct)) { + memcpy(status, data.dptr, sizeof(print_status_struct)); } free(data.dptr); } - return status.qcount; + return status->qcount; +} + +/**************************************************************************** + Determine the number of jobs in a queue. +****************************************************************************/ + +static int print_queue_length(int snum) +{ + fstring keystr; + TDB_DATA data, key; + print_status_struct status; + + /* make sure the database is up to date */ + if (print_cache_expired(snum)) print_queue_update(snum); + + /* also fetch the queue status */ + return get_queue_status(snum, &status); } /*************************************************************************** -- cgit