s3/printing: make clock jump save and use monotonic time for cache timeout
authorBjörn Jacke <bj@sernet.de>
Wed, 15 Sep 2010 16:23:50 +0000 (18:23 +0200)
committerBjörn Jacke <bj@sernet.de>
Wed, 15 Sep 2010 20:43:24 +0000 (22:43 +0200)
source3/printing/pcap.c
source3/printing/printer_list.c

index 3bc8e9e4e29334bb6168761e2787f673670015a4..1b8f46d8e719e73170dea443880c394100d9cf4b 100644 (file)
@@ -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);
index 6392755cf5ae15eb7011648fb0697c7824bc527e..d02ab88663719b5f99714f55e3bda7f5f81d958e 100644 (file)
@@ -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;