]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: clock: provide a function to automatically adjust now_offset
authorWilly Tarreau <w@1wt.eu>
Tue, 16 May 2023 17:01:55 +0000 (19:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 May 2023 07:33:54 +0000 (09:33 +0200)
Right now there's no way to enforce a specific value of now_ms upon
startup in order to compensate for the time it takes to load a config,
specifically when dealing with the health check startup. For this we'd
need to force the now_offset value to compensate for the last known
value of the current date. This patch exposes a function to do exactly
this.

include/haproxy/clock.h
src/clock.c

index 8ce41e79e68e1eb53c0abc06c9fd2f08d1c2fcb4..264363e27b0c18c3cec69fbd69b10c3066838ae6 100644 (file)
@@ -48,6 +48,7 @@ char *timeofday_as_iso_us(int pad);
 uint clock_report_idle(void);
 void clock_leaving_poll(int timeout, int interrupted);
 void clock_entering_poll(void);
+void clock_adjust_now_offset(void);
 
 static inline void clock_update_date(int max_wait, int interrupted)
 {
index 7cf71607fe47055be6741706649e5a087f05aba0..ec2133c8b9e39733e2ad69db7368280242a90ec3 100644 (file)
@@ -304,6 +304,11 @@ void clock_init_process_date(void)
        clock_update_date(0, 1);
 }
 
+void clock_adjust_now_offset(void)
+{
+       HA_ATOMIC_STORE(&now_offset, now_ns - tv_to_ns(&date));
+}
+
 /* must be called once per thread to initialize their thread-local variables.
  * Note that other threads might also be initializing and running in parallel.
  */