summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/advanced.mux14
-rw-r--r--doc/example.mux20
-rw-r--r--src/ClockTAI.cpp24
3 files changed, 41 insertions, 17 deletions
diff --git a/doc/advanced.mux b/doc/advanced.mux
index a5b290d..cdc7768 100644
--- a/doc/advanced.mux
+++ b/doc/advanced.mux
@@ -375,19 +375,7 @@ outputs {
edi {
; EDI uses the UDP protocol. This implementation of EDI does not support
; EDI Packet Resend.
- ;
- ; When both EDI and TIST are enabled, ODR-DabMux will download leap-second
- ; information from the IETF website, and cache it locally in /tmp.
- ;
- ; If your system doesn't have access to internet, you have to take care
- ; to create the file before ODR-DabMux startup. Get it from
- ; http://www.ietf.org/timezones/data/leap-seconds.list
- ; and save it to
- ; /tmp/odr-dabmux-leap-seconds.cache
- ;
- ; Use the RC interface 'get clocktai expiry' command to check how long
- ; your file is still valid. Refresh the file before expiry otherwise
- ; ODR-DabMux will abort.
+ ; If TIST is enabled, requires leap-second information (see example.mux)
destinations {
; The names you give to the destinations have no meaning,
; but have to be unique. You can give them meaningful names to help
diff --git a/doc/example.mux b/doc/example.mux
index 7bd9e3e..1ecffaf 100644
--- a/doc/example.mux
+++ b/doc/example.mux
@@ -31,6 +31,23 @@ general {
; Enable timestamp definition necessary for SFN
; This also enables time encoding using the MNSC.
+ ;
+ ; When TIST is enabled, and either EDI or a ZMQ output with metadata is used,
+ ; ODR-DabMux will download leap-second information from the IETF website,
+ ; and cache it locally in /var/tmp. It will refresh the data by itself
+ ; before it expires.
+ ;
+ ; If it cannot load this information, ODR-DabMux cannot start up!
+ ;
+ ; If your system doesn't have access to internet, you have to take care
+ ; to create the file before ODR-DabMux startup. Get it from
+ ; http://www.ietf.org/timezones/data/leap-seconds.list
+ ; and save it to
+ ; /var/tmp/odr-dabmux-leap-seconds.cache
+ ; Refresh the file before expiry otherwise ODR-DabMux will abort!
+ ;
+ ; Use the RC interface 'get clocktai expiry' command to check how long
+ ; your file is still valid.
tist false
; The management server is a simple TCP server that can present
@@ -189,6 +206,9 @@ outputs {
; Transmit backward compatible metadata containing
; EDI time and UTC offset when TIST is enabled.
+ ;
+ ; If TIST is enabled, requires leap-second information (see example.mux)
+ ;
; WARNING! requires ODR-DabMux to be compiled with
; EDI output, and this will enable leap second download
; as for the EDI output!
diff --git a/src/ClockTAI.cpp b/src/ClockTAI.cpp
index b14de8d..8d693a2 100644
--- a/src/ClockTAI.cpp
+++ b/src/ClockTAI.cpp
@@ -71,9 +71,20 @@ const int64_t ntp_unix_offset = 2208988800L;
// distribution
static array<const char*, 2> tai_urls = {
"http://www.ietf.org/timezones/data/leap-seconds.list",
- "https://raw.githubusercontent.com/eggert/tz/master/leap-seconds.list"};
+ "https://raw.githubusercontent.com/eggert/tz/master/leap-seconds.list",
+};
-static const char* tai_ietf_cache_file = "/tmp/odr-dabmux-leap-seconds.cache";
+// A downloaded bulletin will be saved in the first location of tai_cache_locations
+static array<const char*, 2> tai_cache_locations = {
+ // According to the Filesystem Hierarchy Standard, the data in
+ // /var/tmp "must not be deleted when the system is booted.". This is why
+ // this location has been added.
+ "/var/tmp/odr-dabmux-leap-seconds.cache",
+
+ // The old location in /tmp is less appropriate, as /tmp can get cleared
+ // on a reboot.
+ "/tmp/odr-dabmux-leap-seconds.cache",
+};
ClockTAI::ClockTAI() :
RemoteControllable("clocktai")
@@ -94,7 +105,12 @@ int ClockTAI::get_valid_offset()
offset_valid = true;
}
else {
- load_bulletin_from_file(tai_ietf_cache_file);
+ for (const auto& cache_file : tai_cache_locations) {
+ load_bulletin_from_file(cache_file);
+ if (bulletin_is_valid()) {
+ break;
+ }
+ }
if (bulletin_is_valid()) {
#if TEST
@@ -125,7 +141,7 @@ int ClockTAI::get_valid_offset()
}
if (offset_valid) {
- update_cache(tai_ietf_cache_file);
+ update_cache(tai_cache_locations[0]);
break;
}
}