summaryrefslogtreecommitdiff
path: root/src/timeserver.c
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /src/timeserver.c
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-upstream/1.24.zip
connman-upstream/1.24.tar.gz
connman-upstream/1.24.tar.bz2
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'src/timeserver.c')
-rw-r--r--src/timeserver.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/timeserver.c b/src/timeserver.c
index f3c1220..d41fa40 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -51,10 +51,10 @@ static void save_timeservers(char **servers)
int cnt;
keyfile = __connman_storage_load_global();
- if (keyfile == NULL)
+ if (!keyfile)
keyfile = g_key_file_new();
- for (cnt = 0; servers != NULL && servers[cnt] != NULL; cnt++);
+ for (cnt = 0; servers && servers[cnt]; cnt++);
g_key_file_set_string_list(keyfile, "global", "Timeservers",
(const gchar **)servers, cnt);
@@ -66,13 +66,13 @@ static void save_timeservers(char **servers)
return;
}
-static char **load_timeservers()
+static char **load_timeservers(void)
{
GKeyFile *keyfile;
char **servers = NULL;
keyfile = __connman_storage_load_global();
- if (keyfile == NULL)
+ if (!keyfile)
return NULL;
servers = g_key_file_get_string_list(keyfile, "global",
@@ -83,14 +83,15 @@ static char **load_timeservers()
return servers;
}
-static void resolv_result(GResolvResultStatus status, char **results, gpointer user_data)
+static void resolv_result(GResolvResultStatus status, char **results,
+ gpointer user_data)
{
int i;
DBG("status %d", status);
if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
- if (results != NULL) {
+ if (results) {
for (i = 0; results[i]; i++) {
DBG("result[%d]: %s", i, results[i]);
if (i == 0)
@@ -121,7 +122,7 @@ static void resolv_result(GResolvResultStatus status, char **results, gpointer u
*/
void __connman_timeserver_sync_next()
{
- if (ts_current != NULL) {
+ if (ts_current) {
g_free(ts_current);
ts_current = NULL;
}
@@ -129,7 +130,7 @@ void __connman_timeserver_sync_next()
__connman_ntp_stop();
/* Get the 1st server in the list */
- if (ts_list == NULL)
+ if (!ts_list)
return;
ts_current = ts_list->data;
@@ -158,10 +159,10 @@ GSList *__connman_timeserver_add_list(GSList *server_list,
{
GSList *list = server_list;
- if (timeserver == NULL)
+ if (!timeserver)
return server_list;
- while (list != NULL) {
+ while (list) {
char *existing_server = list->data;
if (strcmp(timeserver, existing_server) == 0)
return server_list;
@@ -192,7 +193,7 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
service_ts_config = connman_service_get_timeservers_config(service);
/* First add Service Timeservers.Configuration to the list */
- for (i = 0; service_ts_config != NULL && service_ts_config[i] != NULL;
+ for (i = 0; service_ts_config && service_ts_config[i];
i++)
list = __connman_timeserver_add_list(list,
service_ts_config[i]);
@@ -200,24 +201,24 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
service_ts = connman_service_get_timeservers(service);
/* First add Service Timeservers via DHCP to the list */
- for (i = 0; service_ts != NULL && service_ts[i] != NULL; i++)
+ for (i = 0; service_ts && service_ts[i]; i++)
list = __connman_timeserver_add_list(list, service_ts[i]);
network = __connman_service_get_network(service);
- if (network != NULL) {
+ if (network) {
index = connman_network_get_index(network);
service_gw = __connman_ipconfig_get_gateway_from_index(index,
CONNMAN_IPCONFIG_TYPE_ALL);
/* Then add Service Gateway to the list */
- if (service_gw != NULL)
+ if (service_gw)
list = __connman_timeserver_add_list(list, service_gw);
}
/* Then add Global Timeservers to the list */
timeservers = load_timeservers();
- for (i = 0; timeservers != NULL && timeservers[i] != NULL; i++)
+ for (i = 0; timeservers && timeservers[i]; i++)
list = __connman_timeserver_add_list(list, timeservers[i]);
g_strfreev(timeservers);
@@ -225,19 +226,19 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
fallback_ts = connman_setting_get_string_list("FallbackTimeservers");
/* Lastly add the fallback servers */
- for (i = 0; fallback_ts != NULL && fallback_ts[i] != NULL; i++)
+ for (i = 0; fallback_ts && fallback_ts[i]; i++)
list = __connman_timeserver_add_list(list, fallback_ts[i]);
return g_slist_reverse(list);
}
-static gboolean ts_recheck(void *user_data)
+static gboolean ts_recheck(gpointer user_data)
{
GSList *ts;
ts = __connman_timeserver_get_all(__connman_service_get_default());
- if (ts == NULL) {
+ if (!ts) {
DBG("timeservers disabled");
return TRUE;
@@ -268,7 +269,7 @@ static void ts_recheck_disable(void)
g_source_remove(ts_recheck_id);
ts_recheck_id = 0;
- if (ts_current != NULL) {
+ if (ts_current) {
g_free(ts_current);
ts_current = NULL;
}
@@ -291,15 +292,15 @@ int __connman_timeserver_sync(struct connman_service *default_service)
{
struct connman_service *service;
- if (default_service != NULL)
+ if (default_service)
service = default_service;
else
service = __connman_service_get_default();
- if (service == NULL)
+ if (!service)
return -EINVAL;
- if (resolv == NULL)
+ if (!resolv)
return 0;
/*
* Before we start creating the new timeserver list we must stop
@@ -319,14 +320,14 @@ int __connman_timeserver_sync(struct connman_service *default_service)
__connman_service_timeserver_changed(service, ts_list);
- if (ts_list == NULL) {
+ if (!ts_list) {
DBG("No timeservers set.");
return 0;
}
ts_recheck_enable();
- __connman_timeserver_sync_next();
+ __connman_timeserver_sync_next();
return 0;
}
@@ -343,21 +344,21 @@ static int timeserver_start(struct connman_service *service)
return -EINVAL;
nameservers = connman_service_get_nameservers(service);
- if (nameservers == NULL)
+ if (!nameservers)
return -EINVAL;
/* Stop an already ongoing resolution, if there is one */
- if (resolv != NULL && resolv_id > 0)
+ if (resolv && resolv_id > 0)
g_resolv_cancel_lookup(resolv, resolv_id);
/* get rid of the old resolver */
- if (resolv != NULL) {
+ if (resolv) {
g_resolv_unref(resolv);
resolv = NULL;
}
resolv = g_resolv_new(i);
- if (resolv == NULL) {
+ if (!resolv) {
g_strfreev(nameservers);
return -ENOMEM;
}
@@ -365,7 +366,7 @@ static int timeserver_start(struct connman_service *service)
if (getenv("CONNMAN_RESOLV_DEBUG"))
g_resolv_set_debug(resolv, resolv_debug, "RESOLV");
- for (i = 0; nameservers[i] != NULL; i++)
+ for (i = 0; nameservers[i]; i++)
g_resolv_add_nameserver(resolv, nameservers[i], 53, 0);
g_strfreev(nameservers);
@@ -373,11 +374,11 @@ static int timeserver_start(struct connman_service *service)
return __connman_timeserver_sync(service);
}
-static void timeserver_stop()
+static void timeserver_stop(void)
{
DBG(" ");
- if (resolv != NULL) {
+ if (resolv) {
g_resolv_unref(resolv);
resolv = NULL;
}
@@ -410,7 +411,7 @@ char **__connman_timeserver_system_get()
static void default_changed(struct connman_service *default_service)
{
- if (default_service != NULL)
+ if (default_service)
timeserver_start(default_service);
else
timeserver_stop();