3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 14:49:24 +01:00

knownnetworks: Fix timestamps comparison

timespec_compare wanted to receive network_info structures as arguments
to compare connected_time timestamps but in one instance we were passing
actual timespec structures.  Add a new function to compare plain timespec
values and switch the names for readability.
This commit is contained in:
Andrew Zaborowski 2018-08-24 03:37:50 +02:00 committed by Denis Kenzior
parent 1024562e1d
commit 58f91a741b

View File

@ -44,12 +44,9 @@ static struct l_queue *known_networks;
static size_t num_known_hidden_networks; static size_t num_known_hidden_networks;
static struct l_fswatch *storage_dir_watch; static struct l_fswatch *storage_dir_watch;
static int timespec_compare(const void *a, const void *b, void *user_data) static int timespec_compare(const struct timespec *tsa,
const struct timespec *tsb)
{ {
const struct network_info *ni_a = a;
const struct network_info *ni_b = b;
const struct timespec *tsa = &ni_a->connected_time;
const struct timespec *tsb = &ni_b->connected_time;
if (tsa->tv_sec > tsb->tv_sec) if (tsa->tv_sec > tsb->tv_sec)
return -1; return -1;
@ -66,6 +63,14 @@ static int timespec_compare(const void *a, const void *b, void *user_data)
return 0; return 0;
} }
static int connected_time_compare(const void *a, const void *b, void *user_data)
{
const struct network_info *ni_a = a;
const struct network_info *ni_b = b;
return timespec_compare(&ni_a->connected_time, &ni_b->connected_time);
}
const char *known_network_get_path(const struct network_info *network) const char *known_network_get_path(const struct network_info *network)
{ {
static char path[256]; static char path[256];
@ -112,7 +117,7 @@ static void known_network_update(struct network_info *orig_network,
else else
network = network_info_add_known(ssid, security); network = network_info_add_known(ssid, security);
if (timespec_compare(&network->connected_time, connected_time, NULL) && if (timespec_compare(&network->connected_time, connected_time) &&
orig_network) { orig_network) {
l_dbus_property_changed(dbus_get_bus(), l_dbus_property_changed(dbus_get_bus(),
known_network_get_path(network), known_network_get_path(network),
@ -120,7 +125,8 @@ static void known_network_update(struct network_info *orig_network,
"LastConnectedTime"); "LastConnectedTime");
l_queue_remove(known_networks, network); l_queue_remove(known_networks, network);
l_queue_insert(known_networks, network, timespec_compare, NULL); l_queue_insert(known_networks, network, connected_time_compare,
NULL);
} }
memcpy(&network->connected_time, connected_time, memcpy(&network->connected_time, connected_time,
@ -145,7 +151,7 @@ static void known_network_update(struct network_info *orig_network,
if (orig_network) if (orig_network)
return; return;
l_queue_insert(known_networks, network, timespec_compare, NULL); l_queue_insert(known_networks, network, connected_time_compare, NULL);
known_network_register_dbus(network); known_network_register_dbus(network);
} }