]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[time] Allow system clock to be adjusted at runtime
authorMichael Brown <mcb30@ipxe.org>
Mon, 13 Jun 2016 14:29:05 +0000 (15:29 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 13 Jun 2016 14:29:05 +0000 (15:29 +0100)
Provide a mechanism to allow an arbitrary adjustment to be applied to
all subsequent calls to time().

Note that the underlying clock source (e.g. the RTC clock) will not be
changed; only the time as reported within iPXE will be affected.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/time.c
src/include/ipxe/time.h
src/include/time.h

index 29a924ebe376db7ba844447f596442426b2766d4..c353ac5bd618db8593c350b98435afff8968da35 100644 (file)
@@ -43,6 +43,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  * 400.
  */
 
+/** Current system clock offset */
+signed long time_offset;
+
 /** Days of week (for debugging) */
 static const char *weekdays[] = {
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
index 4c5bb2a00ec52a9cc418e5cc343753f3117464cb..89bf90e0355274f79545e06078ebca3f8bf3ee75 100644 (file)
@@ -50,11 +50,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 /* Include all architecture-dependent time API headers */
 #include <bits/time.h>
 
+extern signed long time_offset;
+
 /**
- * Get current time in seconds
+ * Get current time in seconds (ignoring system clock offset)
  *
  * @ret time           Time, in seconds
  */
 time_t time_now ( void );
 
+/**
+ * Adjust system clock
+ *
+ * @v delta            Clock adjustment, in seconds
+ */
+static inline __attribute__ (( always_inline )) void
+time_adjust ( signed long delta ) {
+
+       time_offset += delta;
+}
+
 #endif /* _IPXE_TIME_H */
index 462ac6999410d7a905dd50e20c527116af3cbaed..ab93a3dbbf35efbe46f92907c5ba9c4ff5367fad 100644 (file)
@@ -39,10 +39,10 @@ struct tm {
  * @v t                        Time to fill in, or NULL
  * @ret time           Current time
  */
-static inline time_t time ( time_t *t ) {
+static inline __attribute__ (( always_inline )) time_t time ( time_t *t ) {
        time_t now;
 
-       now = time_now();
+       now = ( time_now() + time_offset );
        if ( t )
                *t = now;
        return now;