summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicky Geerts <nicky.geerts@gmail.com>2022-03-07 09:44:32 +0100
committerDaniel Wagner <wagi@monom.org>2022-04-08 09:17:18 +0200
commit78cc1a9225a4b08e3ea2b474259260064cdcdbfe (patch)
treef21bbf584bf4f5d5c0455bb1b0b2dfe79df3c128
parent58b72b96774c1ac0a3b3dbb9f5e3e6e55aa61de0 (diff)
downloadconnman-78cc1a9225a4b08e3ea2b474259260064cdcdbfe.tar.gz
timeserver: include the reason why a timeserver sync is requested
Except for the initial connman_timeserver_start call, and potential updated of the default service, all subsequent calls to resynchronise the timeserver are blocked because of the check whether service equals ts_service in __connman_timeserver_sync. DHCP updates, which could replace the timeserver and nameservers, and state change updates are ignored. As previously suggested by Daniel Wagner on Nov 19th 2019 in a mail to Vivien Henriet, it would be best to pass the reason of the sync call, and add the logic in __connman_timeserver_sync.
-rw-r--r--include/timeserver.h7
-rw-r--r--src/connman.h3
-rw-r--r--src/service.c6
-rw-r--r--src/timeserver.c26
4 files changed, 35 insertions, 7 deletions
diff --git a/include/timeserver.h b/include/timeserver.h
index 48ea1945..3177d4e5 100644
--- a/include/timeserver.h
+++ b/include/timeserver.h
@@ -26,6 +26,13 @@
extern "C" {
#endif
+enum connman_timeserver_sync_reason {
+ CONNMAN_TIMESERVER_SYNC_REASON_START = 0,
+ CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE = 1,
+ CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE = 2,
+ CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE = 3,
+};
+
int __connman_timeserver_system_set(char **server);
#ifdef __cplusplus
diff --git a/src/connman.h b/src/connman.h
index 6405361d..b955d98b 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);
-void __connman_timeserver_sync(struct connman_service *service);
+void __connman_timeserver_sync(struct connman_service *service,
+ enum connman_timeserver_sync_reason reason);
void __connman_timeserver_conf_update(struct connman_service *service);
bool __connman_timeserver_is_synced(void);
diff --git a/src/service.c b/src/service.c
index d4387361..66ab99d8 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1476,7 +1476,8 @@ static void address_updated(struct connman_service *service,
nameserver_add_all(service, type);
start_online_check(service, type);
- __connman_timeserver_sync(service);
+ __connman_timeserver_sync(service,
+ CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE);
}
}
@@ -6506,7 +6507,8 @@ int __connman_service_ipconfig_indicate_state(struct connman_service *service,
if (!is_connected(old_state) && is_connected(new_state))
nameserver_add_all(service, type);
- __connman_timeserver_sync(service);
+ __connman_timeserver_sync(service,
+ CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE);
return service_indicate_state(service);
}
diff --git a/src/timeserver.c b/src/timeserver.c
index 92d0d6bc..4c25d4b8 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -309,7 +309,8 @@ static gboolean ts_recheck(gpointer user_data)
g_slist_free_full(ts, g_free);
service = connman_service_get_default();
- __connman_timeserver_sync(service);
+ __connman_timeserver_sync(service,
+ CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE);
return FALSE;
}
@@ -427,11 +428,27 @@ static void ts_reset(struct connman_service *service)
timeserver_sync_start();
}
-void __connman_timeserver_sync(struct connman_service *service)
+void __connman_timeserver_sync(struct connman_service *service,
+ enum connman_timeserver_sync_reason reason)
{
- if (!service || ts_service == service)
+ if (!service)
return;
+ switch (reason) {
+ case CONNMAN_TIMESERVER_SYNC_REASON_START:
+ case CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE:
+ if (ts_service == service)
+ return;
+ break;
+ case CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE:
+ case CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE:
+ if (ts_service != service)
+ return;
+ break;
+ default:
+ return;
+ }
+
ts_reset(service);
}
@@ -476,7 +493,8 @@ static int timeserver_start(struct connman_service *service)
ts_set_nameservers(service);
- __connman_timeserver_sync(service);
+ __connman_timeserver_sync(service,
+ CONNMAN_TIMESERVER_SYNC_REASON_START);
return 0;
}