summaryrefslogtreecommitdiffstats
path: root/source3
diff options
context:
space:
mode:
authorBjörn Jacke <bj@sernet.de>2010-09-15 18:23:50 +0200
committerBjörn Jacke <bj@sernet.de>2010-09-15 22:43:24 +0200
commitaa7df7b7379cc437515774d0ea91fb106aba5dc8 (patch)
tree0f76ea86aaa23887623368fcca595a27eb4200e1 /source3
parentadf8ca6ff8c6dbc365034a27f8d27a15aa533f97 (diff)
downloadsamba-aa7df7b7379cc437515774d0ea91fb106aba5dc8.tar.gz
samba-aa7df7b7379cc437515774d0ea91fb106aba5dc8.tar.xz
samba-aa7df7b7379cc437515774d0ea91fb106aba5dc8.zip
s3/printing: make clock jump save and use monotonic time for cache timeout
Diffstat (limited to 'source3')
-rw-r--r--source3/printing/pcap.c2
-rw-r--r--source3/printing/printer_list.c27
2 files changed, 15 insertions, 14 deletions
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index 3bc8e9e4e29..1b8f46d8e71 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -82,7 +82,7 @@ void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
bool pcap_cache_add(const char *name, const char *comment)
{
NTSTATUS status;
- time_t t = time(NULL);
+ time_t t = time_mono(NULL);
status = printer_list_set_printer(talloc_tos(), name, comment, t);
return NT_STATUS_IS_OK(status);
diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c
index 6392755cf5a..d02ab886637 100644
--- a/source3/printing/printer_list.c
+++ b/source3/printing/printer_list.c
@@ -218,27 +218,28 @@ done:
bool printer_list_need_refresh(void)
{
NTSTATUS status;
- time_t now = time(NULL);
+ time_t now = time_mono(NULL);
time_t last_refresh;
+ int timediff;
status = printer_list_get_last_refresh(&last_refresh);
if (!NT_STATUS_IS_OK(status)) {
return true;
}
+ timediff = now - last_refresh;
- if (now > last_refresh) {
- /* if refresh occurred last than 1 seconds ago,
- * then we probably don't need to refresh */
- if ((now - last_refresh) < 1) {
- return false;
- }
- } else {
- /* last_refresh newer than now, wow, someone just updated the
- * cache under our nose, do not do again. */
- return false;
+ if (timediff > 1 ) {
+ /* if refresh occurred more than 1s (TODO:use lp_printcap_cache_time) ago,
+ * then we need to refresh */
+ return true;
+ } else if (timediff < 0) {
+ /* last_refresh newer than now. Seems we have no monotonic
+ * clock and the clock was adjusted backwards.
+ * we need to refresh which also resets last_refresh */
+ return true;
}
- return true;
+ return false;
}
NTSTATUS printer_list_mark_reload(void)
@@ -246,7 +247,7 @@ NTSTATUS printer_list_mark_reload(void)
struct db_context *db;
TDB_DATA data;
uint32_t time_h, time_l;
- time_t now = time(NULL);
+ time_t now = time_mono(NULL);
NTSTATUS status;
int len;