Allow to update the existing used service with a new time server
configuration. Instead overloading the __connman_timeservice_sync()
function introduce a new function for updating the currently used
service for time synchronization. By this we document clearly in the
code what is supposed to be updated.
---
src/connman.h | 3 ++-
src/service.c | 4 +---
src/timeserver.c | 53 +++++++++++++++++++++++++++---------------------
3 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index 12e9407f261e..17452a76567f 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -451,7 +451,8 @@ char **__connman_timeserver_system_get();
GSList *__connman_timeserver_add_list(GSList *server_list,
const char *timeserver);
GSList *__connman_timeserver_get_all(struct connman_service *service);
-int __connman_timeserver_sync(struct connman_service *service);
+void __connman_timeserver_sync(struct connman_service *service);
+void __connman_timeserver_conf_update(struct connman_service *service);
enum __connman_dhcpv6_status {
CONNMAN_DHCPV6_STATUS_FAIL = 0,
diff --git a/src/service.c b/src/service.c
index f8ea8ebbe9a4..2c01447e4673 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3746,9 +3746,7 @@ static DBusMessage *set_property(DBusConnection *conn,
service_save(service);
timeservers_configuration_changed(service);
-
- if (service == connman_service_get_default())
- __connman_timeserver_sync(service);
+ __connman_timeserver_conf_update(service);
} else if (g_str_equal(name, "Domains.Configuration")) {
DBusMessageIter entry;
diff --git a/src/timeserver.c b/src/timeserver.c
index 7e4f88ae849a..9e221a26bfc8 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -272,6 +272,7 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
static gboolean ts_recheck(gpointer user_data)
{
+ struct connman_service *service;
GSList *ts;
ts = __connman_timeserver_get_all(connman_service_get_default());
@@ -287,7 +288,8 @@ static gboolean ts_recheck(gpointer user_data)
g_slist_free_full(ts, g_free);
- __connman_timeserver_sync(NULL);
+ service = connman_service_get_default();
+ __connman_timeserver_sync(service);
return FALSE;
}
@@ -327,29 +329,14 @@ static void ts_recheck_enable(void)
NULL);
}
-/*
- * This function must be called every time the default service changes, the
- * service timeserver(s) or gateway changes or the global timeserver(s) changes.
- */
-int __connman_timeserver_sync(struct connman_service *default_service)
+static void ts_reset(struct connman_service *service)
{
- struct connman_service *service;
char **nameservers;
int i;
- if (default_service)
- service = default_service;
- else
- service = connman_service_get_default();
-
- if (!service)
- return -EINVAL;
-
- if (service == ts_service)
- return -EALREADY;
-
if (!resolv)
- return 0;
+ return;
+
/*
* Before we start creating the new timeserver list we must stop
* any ongoing ntp query and server resolution.
@@ -380,17 +367,32 @@ int __connman_timeserver_sync(struct connman_service
*default_service)
if (!timeservers_list) {
DBG("No timeservers set.");
- return 0;
+ return;
}
ts_recheck_enable();
ts_service = service;
timeserver_sync_start();
+}
- return 0;
+void __connman_timeserver_sync(struct connman_service *service)
+{
+ if (!service || service == ts_service)
+ return;
+
+ ts_reset(service);
}
+void __connman_timeserver_conf_update(struct connman_service *service)
+{
+ if (!service || service != ts_service)
+ return;
+
+ ts_reset(service);
+}
+
+
static int timeserver_start(struct connman_service *service)
{
char **nameservers;
@@ -430,7 +432,9 @@ static int timeserver_start(struct connman_service *service)
g_strfreev(nameservers);
}
- return __connman_timeserver_sync(service);
+ __connman_timeserver_sync(service);
+
+ return 0;
}
static void timeserver_stop(void)
@@ -457,9 +461,12 @@ static void timeserver_stop(void)
int __connman_timeserver_system_set(char **servers)
{
+ struct connman_service *service;
+
save_timeservers(servers);
- __connman_timeserver_sync(NULL);
+ service = connman_service_get_default();
+ __connman_timeserver_conf_update(service);
return 0;
}
--
2.29.2
Show replies by date
Hello Daniel,
Your patch seems to solve the problem, but I still need to perform some tests at my
return, and even if I have updated my clock-Add-functions-to-trigger-time-synchronization
patch accordingly, I still not have the exact same behaviour as before (duplicated Time
updated signals, but in a upper layer). I will investigate.
Best Regards
Emmanuel
On Wed, Dec 23, 2020 at 01:18:55PM +0100, Daniel Wagner wrote:
Allow to update the existing used service with a new time server
configuration. Instead overloading the __connman_timeservice_sync()
function introduce a new function for updating the currently used
service for time synchronization. By this we document clearly in the
code what is supposed to be updated.
Patch applied.