diff options
author | Jeremy Allison <jra@samba.org> | 2002-03-07 21:51:54 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-03-07 21:51:54 +0000 |
commit | e2313789c045cc48292c82eb19ce74cdbd9013eb (patch) | |
tree | b54379a770318d946a392a9c1b04d9ad5153bc92 | |
parent | 21b0905042c68ac8d46f7473323f94e74045a669 (diff) | |
download | samba-e2313789c045cc48292c82eb19ce74cdbd9013eb.tar.gz samba-e2313789c045cc48292c82eb19ce74cdbd9013eb.tar.xz samba-e2313789c045cc48292c82eb19ce74cdbd9013eb.zip |
Fix for machines that have their time changed forward, then back. Ensure
that any cached lpq information gathered during that time doesn't
stay around for longer than 1 hour.
Jeremy.
-rw-r--r-- | source/include/printing.h | 7 | ||||
-rw-r--r-- | source/printing/printing.c | 24 |
2 files changed, 25 insertions, 6 deletions
diff --git a/source/include/printing.h b/source/include/printing.h index 40fe964a193..bde2bfa6bdb 100644 --- a/source/include/printing.h +++ b/source/include/printing.h @@ -1,3 +1,6 @@ +#ifndef PRINTING_H_ +#define PRINTING_H_ + /* Unix SMB/Netbios implementation. Version 3.0 @@ -65,5 +68,9 @@ extern struct printif cups_printif; #define UNIX_JOB_START PRINT_MAX_JOBID #define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1) +#define MAX_CACHE_VALID_TIME 3600 + #define PRINT_SPOOL_PREFIX "smbprn." #define PRINT_DATABASE_VERSION 2 + +#endif /* PRINTING_H_ */ diff --git a/source/printing/printing.c b/source/printing/printing.c index 6699b703466..82bd2f722c4 100644 --- a/source/printing/printing.c +++ b/source/printing/printing.c @@ -775,15 +775,27 @@ int print_job_write(int jobid, const char *buf, int size) static BOOL print_cache_expired(int snum) { fstring key; - time_t t2, t = time(NULL); + time_t last_qscan_time, time_now = time(NULL); - slprintf(key, sizeof(key)-1, "CACHE/%s", lp_servicename(snum)); + slprintf(key, sizeof(key), "CACHE/%s", lp_servicename(snum)); dos_to_unix(key, True); /* Convert key to unix-codepage */ - t2 = (time_t)tdb_fetch_int32(tdb, key); - if (t2 == ((time_t)-1) || (t - t2) >= lp_lpqcachetime()) { + last_qscan_time = (time_t)tdb_fetch_int32(tdb, key); + + /* + * Invalidate the queue for 3 reasons. + * (1). last queue scan time == -1. + * (2). Current time - last queue scan time > allowed cache time. + * (3). last queue scan time > current time + MAX_CACHE_VALID_TIME (1 hour by default). + * This last test picks up machines for which the clock has been moved + * forward, an lpq scan done and then the clock moved back. Otherwise + * that last lpq scan would stay around for a loooong loooong time... :-). JRA. + */ + + if (last_qscan_time == ((time_t)-1) || (time_now - last_qscan_time) >= lp_lpqcachetime() || + last_qscan_time > (time_now + MAX_CACHE_VALID_TIME)) { DEBUG(3, ("print cache expired for queue %s \ -(last_cache = %d, time now = %d, qcachetime = %d)\n", lp_servicename(snum), - (int)t2, (int)t, (int)lp_lpqcachetime() )); +(last_qscan_time = %d, time now = %d, qcachetime = %d)\n", lp_servicename(snum), + (int)last_qscan_time, (int)time_now, (int)lp_lpqcachetime() )); return True; } return False; |