summaryrefslogtreecommitdiff
blob: a48a88e9e68d10dcb9bc4ed05346898d7ec8a5d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From 6d254dba01491b994115ecef8c4017fbe5451606 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 16 Apr 2018 12:24:36 +0900
Subject: [PATCH] timesync: establish connection when network become online and
 the manager is not connected yet

This also introduces `manager_is_connected()` helper function, which
returns true when the manager is sending a request, resolving a server
name, or in a poll interval.

Follow-up for 3e85ec072180b6fbec82d715186985536859a29d.
Fixes #8719.
---
 src/timesync/timesyncd-manager.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index cfdc43b0ff2..0c5d3e2d6f7 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -1036,6 +1036,12 @@ static int manager_network_read_link_servers(Manager *m) {
         return r;
 }
 
+static bool manager_is_connected(Manager *m) {
+        /* Return true when the manager is sending a request, resolving a server name, or
+         * in a poll interval. */
+        return m->server_socket >= 0 || m->resolve_query || m->event_timer;
+}
+
 static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         Manager *m = userdata;
         bool changed, connected, online;
@@ -1051,13 +1057,13 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
         online = network_is_online();
 
         /* check if the client is currently connected */
-        connected = m->server_socket >= 0 || m->resolve_query || m->exhausted_servers;
+        connected = manager_is_connected(m);
 
         if (connected && !online) {
                 log_info("No network connectivity, watching for changes.");
                 manager_disconnect(m);
 
-        } else if (!connected && online && changed) {
+        } else if ((!connected || changed) && online) {
                 log_info("Network configuration changed, trying to establish connection.");
 
                 if (m->current_server_address)