From: Alok Barsode <[email protected]>
Add Fallback timeservers via main.conf.
These timeservers are used for time corrections when
there are no valid timeservers provided by the user or by the
network. The list of timeservers which are queried for
timing correction are Timeservers.Configuration (set by the
user), service timeservers(via service), gateway, global
timeservers (via clock API) and fallback timeservers, in that order.
---
src/main.conf | 7 +++++++
src/timeserver.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/main.conf b/src/main.conf
index b4144dd..92ec841 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -5,3 +5,10 @@
# the scan list is empty. In that case, a simple backoff
# mechanism starting from 10s up to 5 minutes will run.
BackgroundScanning = true
+
+# List of Fallback timeservers separated by ",".
+# These timeservers are used for NTP sync when there are
+# no timeserver set by the user or by the service.
+# These can contain mixed combination of fully qualified
+# domain names, IPv4 and IPv6 addresses.
+# FallbackTimeservers =
diff --git a/src/timeserver.c b/src/timeserver.c
index abe56fa..9dd3e30 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -37,6 +37,7 @@ static GSList *ts_list = NULL;
static char **service_ts = NULL;
static const char *service_gw = NULL;
static char **service_ts_config = NULL;
+static char **fallback_ts = NULL;
static GResolv *resolv = NULL;
static int resolv_id = 0;
@@ -88,6 +89,27 @@ static char **load_timeservers()
return servers;
}
+static void load_fallback_timeservers()
+{
+ GKeyFile *keyfile;
+ GError *error = NULL;
+
+ keyfile = __connman_storage_load_mainconf();
+ if (keyfile == NULL)
+ return;
+
+ g_key_file_set_list_separator(keyfile, ',');
+
+ fallback_ts = g_key_file_get_string_list(keyfile, "General",
+ "FallbackTimeservers", NULL,
&error);
+ if (error != NULL) {
+ DBG("Error loading fallback timeservers: %s", error->message);
+ g_error_free(error);
+ }
+
+ g_key_file_free(keyfile);
+}
+
static void resolv_result(GResolvResultStatus status, char **results, gpointer
user_data)
{
int i;
@@ -222,6 +244,13 @@ int __connman_timeserver_sync(struct connman_service
*service)
for (i=0; timeservers != NULL && timeservers[i] != NULL; i++)
ts_list = g_slist_append(ts_list, g_strdup(timeservers[i]));
+ if (fallback_ts == NULL)
+ load_fallback_timeservers();
+
+ /* Lastly add the fallback servers */
+ for (i=0; fallback_ts != NULL && fallback_ts[i] != NULL; i++)
+ ts_list = g_slist_append(ts_list, g_strdup(fallback_ts[i]));
+
if (g_slist_length(ts_list) == 0) {
DBG("No timeservers set.");
return 0;
@@ -298,6 +327,11 @@ static void timeserver_stop()
ts_list = NULL;
+ if (fallback_ts != NULL)
+ g_strfreev(fallback_ts);
+
+ fallback_ts = NULL;
+
__connman_ntp_stop();
}
--
1.7.5.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman