Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. Re: [PATCH] service: Do no leak stats FDs (Daniel Wagner)
2. [PATCH v1 0/5] Retry NTP servers periodically on startup
(Daniel Wagner)
3. [PATCH v1 2/5] ntp: Add callback to __connman_ntp_start()
(Daniel Wagner)
4. [PATCH v1 1/5] ntp: Move variables into data struct
(Daniel Wagner)
5. [PATCH v1 3/5] timeserver: Rename
__connman_timeserver_sync_next() to sync_next() (Daniel Wagner)
----------------------------------------------------------------------
Message: 1
Date: Wed, 17 Jan 2018 08:28:53 +0100
From: Daniel Wagner <[email protected]>
To: Richard Genoud <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] service: Do no leak stats FDs
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Hi Richard,
On 11/12/2017 08:04 PM, Daniel Wagner wrote:
> ConnMan leaks the stats file descriptor. The disconnect path is
> slightly more complex then it one would suspect. So when the service
> goes from ONLINE to IDLE because the Ethernet cable was unplugged, the
> service will retry to connect. This ends up opening up another FD for
> the stats file. Eventually the service will be removed but we bail out
> a early in the __connman_service_disconnect() function and never call
> __connann_stats_servicde_unregister. Let's move the unregister up so
> that we always call it.
I decided to apply this patch since it fixes a bug on my machine.
Unfortunatly, I was not able so far to figure out where we leak the FDs
for the IPv6 case.
Thanks,
Daniel
------------------------------
Message: 2
Date: Wed, 17 Jan 2018 08:50:27 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v1 0/5] Retry NTP servers periodically on startup
Message-ID: <[email protected]>
Hi,
This is the attempt to fix the outstanding CM-636 bug. This is still
not completely finished. There is some more potential to cleanup the
timeserver code. But I thought maybe someone wants to test it. You can
install a iptables rule to see if the retry logic works.
iptables -A OUTPUT -p tcp --dport 123 -j DROP
iptables -A OUTPUT -p udp --dport 123 -j DROP
This should do the trick.
Thanks,
Daniel
Daniel Wagner (5):
ntp: Move variables into data struct
ntp: Add callback to __connman_ntp_start()
timeserver: Rename __connman_timeserver_sync_next() to sync_next()
timeserver: Retry NTP servers periodically on startup
ntp: Report EPERM to timeserver
src/connman.h | 5 +-
src/ntp.c | 218 +++++++++++++++++++++++++++++--------------------------
src/timeserver.c | 103 ++++++++++++++++++++++----
3 files changed, 205 insertions(+), 121 deletions(-)
--
2.14.3
------------------------------
Message: 3
Date: Wed, 17 Jan 2018 08:50:29 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v1 2/5] ntp: Add callback to __connman_ntp_start()
Message-ID: <[email protected]>
Introduce a callback to notify timeserver if an operation was
successfull or not. The NTP layer should not be involved in the logic
of timerserver selection.
While at it, we also notify timerserver of any failure during decoding
the received NTP frame. Until now we just did that when we were not
able to communicate with the peer. The timerserver code is now able to
select the next server.
---
src/connman.h | 4 +++-
src/ntp.c | 29 +++++++++++++++--------------
src/timeserver.c | 13 +++++++++++--
3 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index 92bb8e5d66a6..efeb5fe42f66 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -503,7 +503,9 @@ int __connman_connection_get_vpn_index(int phy_index);
bool __connman_connection_update_gateway(void);
-int __connman_ntp_start(char *server);
+typedef void (*__connman_ntp_cb_t) (bool success, void *user_data);
+int __connman_ntp_start(char *server, __connman_ntp_cb_t callback,
+ void *user_data);
void __connman_ntp_stop();
int __connman_wpad_init(void);
diff --git a/src/ntp.c b/src/ntp.c
index 1d973131593a..c0f1d3d45c4a 100644
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -128,6 +128,8 @@ struct ntp_data {
guint channel_watch;
gint poll_id;
uint32_t timeout;
+ __connman_ntp_cb_t cb;
+ void *user_data;
};
static struct ntp_data *ntp_data;
@@ -148,16 +150,6 @@ static void free_ntp_data(struct ntp_data *nd)
static void send_packet(struct ntp_data *nd, struct sockaddr *server,
uint32_t timeout);
-static void next_server(struct ntp_data *data)
-{
- if (data->timeserver) {
- g_free(data->timeserver);
- data->timeserver = NULL;
- }
-
- __connman_timeserver_sync_next();
-}
-
static gboolean send_timeout(gpointer user_data)
{
struct ntp_data *nd = user_data;
@@ -165,7 +157,7 @@ static gboolean send_timeout(gpointer user_data)
DBG("send timeout %u (retries %d)", nd->timeout, nd->retries);
if (nd->retries++ == NTP_SEND_RETRIES)
- next_server(nd);
+ nd->cb(false, nd->user_data);
else
send_packet(nd, (struct sockaddr *)&nd->timeserver_addr,
nd->timeout << 1);
@@ -221,7 +213,7 @@ static void send_packet(struct ntp_data *nd, struct
sockaddr *server,
errno, strerror(errno));
if (errno == ENETUNREACH)
- __connman_timeserver_sync_next();
+ nd->cb(false, nd->user_data);
return;
}
@@ -303,7 +295,7 @@ static void decode_msg(struct ntp_data *nd, void *base,
size_t len,
connman_info("Skipping server %s KoD code %c%c%c%c",
nd->timeserver, code >> 24, code >> 16 & 0xff,
code >> 8 & 0xff, code & 0xff);
- next_server(nd);
+ nd->cb(false, nd->user_data);
return;
}
@@ -311,6 +303,7 @@ static void decode_msg(struct ntp_data *nd, void *base,
size_t len,
if (NTP_FLAGS_LI_DECODE(msg->flags) == NTP_FLAG_LI_NOTINSYNC) {
DBG("ignoring unsynchronized peer");
+ nd->cb(false, nd->user_data);
return;
}
@@ -321,12 +314,14 @@ static void decode_msg(struct ntp_data *nd, void *base,
size_t len,
NTP_FLAG_VN_VER4,
NTP_FLAGS_VN_DECODE(msg->flags));
} else {
DBG("unsupported version %d",
NTP_FLAGS_VN_DECODE(msg->flags));
+ nd->cb(false, nd->user_data);
return;
}
}
if (NTP_FLAGS_MD_DECODE(msg->flags) != NTP_FLAG_MD_SERVER) {
DBG("unsupported mode %d", NTP_FLAGS_MD_DECODE(msg->flags));
+ nd->cb(false, nd->user_data);
return;
}
@@ -397,11 +392,14 @@ static void decode_msg(struct ntp_data *nd, void *base,
size_t len,
if (adjtimex(&tmx) < 0) {
connman_error("Failed to adjust time");
+ nd->cb(false, nd->user_data);
return;
}
DBG("interval/delta/delay/drift %fs/%+.3fs/%.3fs/%+ldppm",
LOGTOD(msg->poll), offset, delay, tmx.freq / 65536);
+
+ nd->cb(true, nd->user_data);
}
static gboolean received_data(GIOChannel *channel, GIOCondition condition,
@@ -581,7 +579,8 @@ static void start_ntp(struct ntp_data *nd)
NTP_SEND_TIMEOUT);
}
-int __connman_ntp_start(char *server)
+int __connman_ntp_start(char *server, __connman_ntp_cb_t callback,
+ void *user_data)
{
if (!server)
return -EINVAL;
@@ -595,6 +594,8 @@ int __connman_ntp_start(char *server)
ntp_data = g_new0(struct ntp_data, 1);
ntp_data->timeserver = g_strdup(server);
+ ntp_data->cb = callback;
+ ntp_data->user_data = user_data;
DBG("timerserver %s", server);
start_ntp(ntp_data);
diff --git a/src/timeserver.c b/src/timeserver.c
index 0e555a73c3bf..d06d1bb3ba9a 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -45,6 +45,15 @@ static void resolv_debug(const char *str, void *data)
{
connman_info("%s: %s\n", (const char *) data, str);
}
+
+static void ntp_callback(bool success, void *user_data)
+{
+ DBG("success %d", success);
+
+ if (!success)
+ __connman_timeserver_sync_next();
+}
+
static void save_timeservers(char **servers)
{
GKeyFile *keyfile;
@@ -103,7 +112,7 @@ static void resolv_result(GResolvResultStatus status, char
**results,
DBG("Using timeserver %s", results[0]);
- __connman_ntp_start(results[0]);
+ __connman_ntp_start(results[0], ntp_callback, NULL);
return;
}
@@ -141,7 +150,7 @@ void __connman_timeserver_sync_next()
if (connman_inet_check_ipaddress(ts_current) > 0) {
DBG("Using timeserver %s", ts_current);
- __connman_ntp_start(ts_current);
+ __connman_ntp_start(ts_current, ntp_callback, NULL);
return;
}
--
2.14.3
------------------------------
Message: 4
Date: Wed, 17 Jan 2018 08:50:28 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v1 1/5] ntp: Move variables into data struct
Message-ID: <[email protected]>
Instead having 'global' variables, move them into a data structure and
hand the pointer to the function. This streamlines it with the rest of
the code base.
---
src/ntp.c | 201 +++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 106 insertions(+), 95 deletions(-)
diff --git a/src/ntp.c b/src/ntp.c
index 0e80c3e56518..1d973131593a 100644
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -118,23 +118,41 @@ struct ntp_msg {
#define NTP_PRECISION_US -19
#define NTP_PRECISION_NS -29
-static guint channel_watch = 0;
-static struct timespec mtx_time;
-static int transmit_fd = 0;
-
-static char *timeserver = NULL;
-static struct sockaddr_in6 timeserver_addr;
-static gint poll_id = 0;
-static gint timeout_id = 0;
-static guint retries = 0;
+struct ntp_data {
+ char *timeserver;
+ struct sockaddr_in6 timeserver_addr;
+ struct timespec mtx_time;
+ int transmit_fd;
+ gint timeout_id;
+ guint retries;
+ guint channel_watch;
+ gint poll_id;
+ uint32_t timeout;
+};
+
+static struct ntp_data *ntp_data;
+
+static void free_ntp_data(struct ntp_data *nd)
+{
+ if (nd->poll_id)
+ g_source_remove(nd->poll_id);
+ if (nd->timeout_id)
+ g_source_remove(nd->timeout_id);
+ if (nd->channel_watch)
+ g_source_remove(nd->channel_watch);
+ if (nd->timeserver)
+ g_free(nd->timeserver);
+ g_free(nd);
+}
-static void send_packet(int fd, struct sockaddr *server, uint32_t timeout);
+static void send_packet(struct ntp_data *nd, struct sockaddr *server,
+ uint32_t timeout);
-static void next_server(void)
+static void next_server(struct ntp_data *data)
{
- if (timeserver) {
- g_free(timeserver);
- timeserver = NULL;
+ if (data->timeserver) {
+ g_free(data->timeserver);
+ data->timeserver = NULL;
}
__connman_timeserver_sync_next();
@@ -142,19 +160,21 @@ static void next_server(void)
static gboolean send_timeout(gpointer user_data)
{
- uint32_t timeout = GPOINTER_TO_UINT(user_data);
+ struct ntp_data *nd = user_data;
- DBG("send timeout %u (retries %d)", timeout, retries);
+ DBG("send timeout %u (retries %d)", nd->timeout, nd->retries);
- if (retries++ == NTP_SEND_RETRIES)
- next_server();
+ if (nd->retries++ == NTP_SEND_RETRIES)
+ next_server(nd);
else
- send_packet(transmit_fd, (struct sockaddr *)×erver_addr,
timeout << 1);
+ send_packet(nd, (struct sockaddr *)&nd->timeserver_addr,
+ nd->timeout << 1);
return FALSE;
}
-static void send_packet(int fd, struct sockaddr *server, uint32_t timeout)
+static void send_packet(struct ntp_data *nd, struct sockaddr *server,
+ uint32_t timeout)
{
struct ntp_msg msg;
struct timeval transmit_timeval;
@@ -177,22 +197,22 @@ static void send_packet(int fd, struct sockaddr *server,
uint32_t timeout)
if (server->sa_family == AF_INET) {
size = sizeof(struct sockaddr_in);
- addr = (void *)&(((struct sockaddr_in
*)×erver_addr)->sin_addr);
+ addr = (void *)&(((struct sockaddr_in
*)&nd->timeserver_addr)->sin_addr);
} else if (server->sa_family == AF_INET6) {
size = sizeof(struct sockaddr_in6);
- addr = (void *)×erver_addr.sin6_addr;
+ addr = (void *)&nd->timeserver_addr.sin6_addr;
} else {
connman_error("Family is neither ipv4 nor ipv6");
return;
}
gettimeofday(&transmit_timeval, NULL);
- clock_gettime(CLOCK_MONOTONIC, &mtx_time);
+ clock_gettime(CLOCK_MONOTONIC, &nd->mtx_time);
msg.xmttime.seconds = htonl(transmit_timeval.tv_sec + OFFSET_1900_1970);
msg.xmttime.fraction = htonl(transmit_timeval.tv_usec * 1000);
- len = sendto(fd, &msg, sizeof(msg), MSG_DONTWAIT,
+ len = sendto(nd->transmit_fd, &msg, sizeof(msg), MSG_DONTWAIT,
server, size);
if (len < 0) {
@@ -218,34 +238,35 @@ static void send_packet(int fd, struct sockaddr *server,
uint32_t timeout)
* trying another server.
*/
- timeout_id = g_timeout_add_seconds(timeout, send_timeout,
+ nd->timeout_id = g_timeout_add_seconds(timeout, send_timeout,
GUINT_TO_POINTER(timeout));
}
static gboolean next_poll(gpointer user_data)
{
- poll_id = 0;
+ struct ntp_data *nd = user_data;
+ nd->poll_id = 0;
- if (!timeserver || transmit_fd == 0)
+ if (!nd->timeserver || nd->transmit_fd == 0)
return FALSE;
- send_packet(transmit_fd, (struct sockaddr *)×erver_addr,
NTP_SEND_TIMEOUT);
+ send_packet(nd, (struct sockaddr *)&nd->timeserver_addr,
NTP_SEND_TIMEOUT);
return FALSE;
}
-static void reset_timeout(void)
+static void reset_timeout(struct ntp_data *nd)
{
- if (timeout_id > 0) {
- g_source_remove(timeout_id);
- timeout_id = 0;
+ if (nd->timeout_id > 0) {
+ g_source_remove(nd->timeout_id);
+ nd->timeout_id = 0;
}
- retries = 0;
+ nd->retries = 0;
}
-static void decode_msg(void *base, size_t len, struct timeval *tv,
- struct timespec *mrx_time)
+static void decode_msg(struct ntp_data *nd, void *base, size_t len,
+ struct timeval *tv, struct timespec *mrx_time)
{
struct ntp_msg *msg = base;
double m_delta, org, rec, xmt, dst;
@@ -280,9 +301,9 @@ static void decode_msg(void *base, size_t len, struct
timeval *tv,
uint32_t code = ntohl(msg->refid);
connman_info("Skipping server %s KoD code %c%c%c%c",
- timeserver, code >> 24, code >> 16 & 0xff,
+ nd->timeserver, code >> 24, code >> 16 & 0xff,
code >> 8 & 0xff, code & 0xff);
- next_server();
+ next_server(nd);
return;
}
@@ -309,8 +330,8 @@ static void decode_msg(void *base, size_t len, struct
timeval *tv,
return;
}
- m_delta = mrx_time->tv_sec - mtx_time.tv_sec +
- 1.0e-9 * (mrx_time->tv_nsec - mtx_time.tv_nsec);
+ m_delta = mrx_time->tv_sec - nd->mtx_time.tv_sec +
+ 1.0e-9 * (mrx_time->tv_nsec - nd->mtx_time.tv_nsec);
org = tv->tv_sec + (1.0e-6 * tv->tv_usec) - m_delta + OFFSET_1900_1970;
rec = ntohl(msg->rectime.seconds) +
@@ -328,18 +349,19 @@ static void decode_msg(void *base, size_t len, struct
timeval *tv,
/* Remove the timeout, as timeserver has responded */
- reset_timeout();
+ reset_timeout(nd);
/*
* Now poll the server every transmit_delay seconds
* for time correction.
*/
- if (poll_id > 0)
- g_source_remove(poll_id);
+ if (nd->poll_id > 0)
+ g_source_remove(nd->poll_id);
- DBG("Timeserver %s, next sync in %d seconds", timeserver,
transmit_delay);
+ DBG("Timeserver %s, next sync in %d seconds", nd->timeserver,
+ transmit_delay);
- poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL);
+ nd->poll_id = g_timeout_add_seconds(transmit_delay, next_poll, nd);
if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) {
tmx.modes = ADJ_STATUS | ADJ_NANO | ADJ_OFFSET | ADJ_TIMECONST
| ADJ_MAXERROR | ADJ_ESTERROR;
@@ -385,6 +407,7 @@ static void decode_msg(void *base, size_t len, struct
timeval *tv,
static gboolean received_data(GIOChannel *channel, GIOCondition condition,
gpointer user_data)
{
+ struct ntp_data *nd = user_data;
unsigned char buf[128];
struct sockaddr_in6 sender_addr;
struct msghdr msg;
@@ -401,7 +424,7 @@ static gboolean received_data(GIOChannel *channel,
GIOCondition condition,
if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
connman_error("Problem with timer server channel");
- channel_watch = 0;
+ nd->channel_watch = 0;
return FALSE;
}
@@ -424,11 +447,11 @@ static gboolean received_data(GIOChannel *channel,
GIOCondition condition,
if (sender_addr.sin6_family == AF_INET) {
size = 4;
- addr_ptr = &((struct sockaddr_in *)×erver_addr)->sin_addr;
+ addr_ptr = &((struct sockaddr_in
*)&nd->timeserver_addr)->sin_addr;
src_ptr = &((struct sockaddr_in *)&sender_addr)->sin_addr;
} else if (sender_addr.sin6_family == AF_INET6) {
size = 16;
- addr_ptr = &((struct sockaddr_in6
*)×erver_addr)->sin6_addr;
+ addr_ptr = &((struct sockaddr_in6
*)&nd->timeserver_addr)->sin6_addr;
src_ptr = &((struct sockaddr_in6 *)&sender_addr)->sin6_addr;
} else {
connman_error("Not a valid family type");
@@ -452,12 +475,12 @@ static gboolean received_data(GIOChannel *channel,
GIOCondition condition,
}
}
- decode_msg(iov.iov_base, iov.iov_len, tv, &mrx_time);
+ decode_msg(nd, iov.iov_base, iov.iov_len, tv, &mrx_time);
return TRUE;
}
-static void start_ntp(char *server)
+static void start_ntp(struct ntp_data *nd)
{
GIOChannel *channel;
struct addrinfo hint;
@@ -470,14 +493,11 @@ static void start_ntp(char *server)
int tos = IPTOS_LOWDELAY, timestamp = 1;
int ret;
- if (!server)
- return;
-
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_DGRAM;
hint.ai_flags = AI_NUMERICHOST | AI_PASSIVE;
- ret = getaddrinfo(server, NULL, &hint, &info);
+ ret = getaddrinfo(nd->timeserver, NULL, &hint, &info);
if (ret) {
connman_error("cannot get server info");
@@ -486,18 +506,18 @@ static void start_ntp(char *server)
family = info->ai_family;
- memcpy(×erver_addr, info->ai_addr, info->ai_addrlen);
+ memcpy(&ntp_data->timeserver_addr, info->ai_addr, info->ai_addrlen);
freeaddrinfo(info);
memset(&in6addr, 0, sizeof(in6addr));
if (family == AF_INET) {
- ((struct sockaddr_in *)×erver_addr)->sin_port = htons(123);
+ ((struct sockaddr_in *)&ntp_data->timeserver_addr)->sin_port =
htons(123);
in4addr = (struct sockaddr_in *)&in6addr;
in4addr->sin_family = family;
addr = (struct sockaddr *)in4addr;
size = sizeof(struct sockaddr_in);
} else if (family == AF_INET6) {
- timeserver_addr.sin6_port = htons(123);
+ ntp_data->timeserver_addr.sin6_port = htons(123);
in6addr.sin6_family = family;
addr = (struct sockaddr *)&in6addr;
size = sizeof(in6addr);
@@ -506,42 +526,42 @@ static void start_ntp(char *server)
return;
}
- DBG("server %s family %d", server, family);
+ DBG("server %s family %d", nd->timeserver, family);
- if (channel_watch > 0)
+ if (nd->channel_watch > 0)
goto send;
- transmit_fd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ nd->transmit_fd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- if (transmit_fd <= 0) {
+ if (nd->transmit_fd <= 0) {
connman_error("Failed to open time server socket");
return;
}
- if (bind(transmit_fd, (struct sockaddr *) addr, size) < 0) {
+ if (bind(nd->transmit_fd, (struct sockaddr *) addr, size) < 0) {
connman_error("Failed to bind time server socket");
- close(transmit_fd);
+ close(nd->transmit_fd);
return;
}
if (family == AF_INET) {
- if (setsockopt(transmit_fd, IPPROTO_IP, IP_TOS, &tos,
sizeof(tos)) < 0) {
+ if (setsockopt(nd->transmit_fd, IPPROTO_IP, IP_TOS, &tos,
sizeof(tos)) < 0) {
connman_error("Failed to set type of service option");
- close(transmit_fd);
+ close(nd->transmit_fd);
return;
}
}
- if (setsockopt(transmit_fd, SOL_SOCKET, SO_TIMESTAMP, ×tamp,
+ if (setsockopt(nd->transmit_fd, SOL_SOCKET, SO_TIMESTAMP, ×tamp,
sizeof(timestamp)) < 0) {
connman_error("Failed to enable timestamp support");
- close(transmit_fd);
+ close(nd->transmit_fd);
return;
}
- channel = g_io_channel_unix_new(transmit_fd);
+ channel = g_io_channel_unix_new(nd->transmit_fd);
if (!channel) {
- close(transmit_fd);
+ close(nd->transmit_fd);
return;
}
@@ -550,52 +570,43 @@ static void start_ntp(char *server)
g_io_channel_set_close_on_unref(channel, TRUE);
- channel_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
+ nd->channel_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- received_data, NULL, NULL);
+ received_data, nd, NULL);
g_io_channel_unref(channel);
send:
- send_packet(transmit_fd, (struct sockaddr*)×erver_addr,
NTP_SEND_TIMEOUT);
+ send_packet(nd, (struct sockaddr*)&ntp_data->timeserver_addr,
+ NTP_SEND_TIMEOUT);
}
int __connman_ntp_start(char *server)
{
- DBG("%s", server);
-
if (!server)
return -EINVAL;
- if (timeserver)
- g_free(timeserver);
+ if (ntp_data) {
+ connman_warn("ntp_data is not NULL (timerserver %s)",
+ ntp_data->timeserver);
+ free_ntp_data(ntp_data);
+ }
- timeserver = g_strdup(server);
+ ntp_data = g_new0(struct ntp_data, 1);
- start_ntp(timeserver);
+ ntp_data->timeserver = g_strdup(server);
+
+ DBG("timerserver %s", server);
+ start_ntp(ntp_data);
return 0;
}
void __connman_ntp_stop()
{
- DBG("");
-
- if (poll_id > 0) {
- g_source_remove(poll_id);
- poll_id = 0;
- }
-
- reset_timeout();
-
- if (channel_watch > 0) {
- g_source_remove(channel_watch);
- channel_watch = 0;
- transmit_fd = 0;
- }
-
- if (timeserver) {
- g_free(timeserver);
- timeserver = NULL;
+ if (ntp_data) {
+ DBG("timeserver %s", ntp_data->timeserver);
+ free_ntp_data(ntp_data);
}
+ ntp_data = NULL;
}
--
2.14.3
------------------------------
Message: 5
Date: Wed, 17 Jan 2018 08:50:30 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v1 3/5] timeserver: Rename
__connman_timeserver_sync_next() to sync_next()
Message-ID: <[email protected]>
We do not have any user outside of timeserver.c. So let's make it a
local function.
---
src/connman.h | 1 -
src/timeserver.c | 10 ++++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index efeb5fe42f66..6d1831b15358 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -448,7 +448,6 @@ 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_next();
enum __connman_dhcpv6_status {
CONNMAN_DHCPV6_STATUS_FAIL = 0,
diff --git a/src/timeserver.c b/src/timeserver.c
index d06d1bb3ba9a..68d443494abf 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -41,6 +41,8 @@ static int ts_recheck_id = 0;
static GResolv *resolv = NULL;
static int resolv_id = 0;
+static void sync_next(void);
+
static void resolv_debug(const char *str, void *data)
{
connman_info("%s: %s\n", (const char *) data, str);
@@ -51,7 +53,7 @@ static void ntp_callback(bool success, void *user_data)
DBG("success %d", success);
if (!success)
- __connman_timeserver_sync_next();
+ sync_next();
}
static void save_timeservers(char **servers)
@@ -119,7 +121,7 @@ static void resolv_result(GResolvResultStatus status, char
**results,
}
/* If resolving fails, move to the next server */
- __connman_timeserver_sync_next();
+ sync_next();
}
/*
@@ -129,7 +131,7 @@ static void resolv_result(GResolvResultStatus status, char
**results,
* timeserver. We only resolve the URLs. Once we have an IP for the NTP
* server, we start querying it for time corrections.
*/
-void __connman_timeserver_sync_next()
+static void sync_next()
{
if (ts_current) {
g_free(ts_current);
@@ -349,7 +351,7 @@ int __connman_timeserver_sync(struct connman_service
*default_service)
ts_recheck_enable();
- __connman_timeserver_sync_next();
+ sync_next();
return 0;
}
--
2.14.3
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 27, Issue 12
***************************************