From: Alok Barsode <[email protected]>

Trigger NTP sync on default service going to READY/ONLINE state
instead of triggering NTP sync on ONLINE state only. This makes
sense for local ntp servers even if the wispr check fails.
---
 src/service.c    |    5 -----
 src/timeserver.c |   32 ++++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/service.c b/src/service.c
index a295b8d..5bfd984 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4116,9 +4116,6 @@ static int service_indicate_state(struct connman_service 
*service)
                }
        }
 
-       if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
-               __connman_timeserver_sync(service);
-
        if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
                connman_bool_t reconnect;
 
@@ -4188,8 +4185,6 @@ static int service_indicate_state(struct connman_service 
*service)
                dns_changed(service);
                domain_changed(service);
 
-               __connman_timeserver_stop();
-
                __connman_notifier_disconnect(service->type);
 
                /*
diff --git a/src/timeserver.c b/src/timeserver.c
index 08dd81b..cd86746 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -155,11 +155,20 @@ void __connman_timeserver_sync_next()
                                                NULL);
 }
 
-int __connman_timeserver_sync(struct connman_service *service)
+int __connman_timeserver_sync(struct connman_service *default_service)
 {
-       char **nameservers = NULL;
+       struct connman_service *service;
+       char **nameservers;
        int i;
 
+       if (default_service != NULL)
+               service = default_service;
+       else
+               service = __connman_service_get_default();
+
+       if (service == NULL)
+               return -EINVAL;
+
        DBG("service %p", service);
 
        i = __connman_service_get_index(service);
@@ -242,14 +251,33 @@ char **__connman_timeserver_system_get()
        return servers;
 }
 
+static void default_changed(struct connman_service *default_service)
+{
+       DBG("");
+
+       if (service != NULL)
+               __connman_timeserver_sync(default_service);
+       else
+               __connman_timeserver_stop();
+}
+
+static struct connman_notifier timeserver_notifier = {
+       .name                   = "timeserver",
+       .default_changed        = default_changed,
+};
+
 int __connman_timeserver_init(void)
 {
        DBG("");
 
+       connman_notifier_register(&timeserver_notifier);
+
        return 0;
 }
 
 void __connman_timeserver_cleanup(void)
 {
        DBG("");
+
+       connman_notifier_unregister(&timeserver_notifier);
 }
-- 
1.7.5.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to