diff options
author | Michael Brown | 2017-01-26 12:39:25 +0100 |
---|---|---|
committer | Michael Brown | 2017-01-26 13:26:54 +0100 |
commit | 41f786cc0a392c238068919709a63985134bb9b1 (patch) | |
tree | 1ac9e7b321eeb5156836c1d625b2cf7eb3457e5a /src/core | |
parent | [intel] Add INTEL_NO_PHY_RST for I219-LM (2) (diff) | |
download | ipxe-41f786cc0a392c238068919709a63985134bb9b1.tar.gz ipxe-41f786cc0a392c238068919709a63985134bb9b1.tar.xz ipxe-41f786cc0a392c238068919709a63985134bb9b1.zip |
[settings] Add "unixtime" builtin setting to expose the current time
Expose the current wall-clock time (in seconds since the Epoch), since
this is often useful in captured boot logs and can also be useful when
checking unexpected X.509 certificate validation failures.
Use a :uint32 setting to avoid Y2K38 rollover, thereby ensuring that
this will eventually be somebody else's problem.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/settings.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/core/settings.c b/src/core/settings.c index c306054d..e60a882a 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <byteswap.h> #include <errno.h> #include <assert.h> +#include <time.h> #include <ipxe/in.h> #include <ipxe/ip.h> #include <ipxe/ipv6.h> @@ -2553,6 +2554,38 @@ struct builtin_setting version_builtin_setting __builtin_setting = { }; /** + * Fetch current time setting + * + * @v data Buffer to fill with setting data + * @v len Length of buffer + * @ret len Length of setting data, or negative error + */ +static int unixtime_fetch ( void *data, size_t len ) { + uint32_t content; + + /* Return current time */ + content = htonl ( time(NULL) ); + if ( len > sizeof ( content ) ) + len = sizeof ( content ); + memcpy ( data, &content, len ); + return sizeof ( content ); +} + +/** Current time setting */ +const struct setting unixtime_setting __setting ( SETTING_MISC, unixtime ) = { + .name = "unixtime", + .description = "Seconds since the Epoch", + .type = &setting_type_uint32, + .scope = &builtin_scope, +}; + +/** Current time built-in setting */ +struct builtin_setting unixtime_builtin_setting __builtin_setting = { + .setting = &unixtime_setting, + .fetch = unixtime_fetch, +}; + +/** * Fetch built-in setting * * @v settings Settings block |