summaryrefslogtreecommitdiffstats
path: root/source3/printing/printing.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-11-21 00:30:15 +0000
committerJeremy Allison <jra@samba.org>2000-11-21 00:30:15 +0000
commit2bd3a436fd6ed218bced476b502d24f317511fb2 (patch)
tree6f3ae1d58e9580fec11b192a3114a515867d9e30 /source3/printing/printing.c
parentac4d2775618a9ac3428d60bf667e3b968d634799 (diff)
downloadsamba-2bd3a436fd6ed218bced476b502d24f317511fb2.tar.gz
samba-2bd3a436fd6ed218bced476b502d24f317511fb2.tar.xz
samba-2bd3a436fd6ed218bced476b502d24f317511fb2.zip
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)
Diffstat (limited to 'source3/printing/printing.c')
-rw-r--r--source3/printing/printing.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 1eb6c275553..06487156995 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);
}
/***************************************************************************