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

knownnetworks: use l_path_get_mtime

Rather than using timespec directly, ELL has a convenient API
to get the elapsed microseconds as a uint64_t. This can then
be used with the other l_time_ APIs for comparison.

This patch removes timespec from network_info and updates
to use l_time_* API's for sorting.
This commit is contained in:
James Prestwood 2019-08-21 12:06:10 -07:00 committed by Denis Kenzior
parent de589f3183
commit 6ff86abb41
3 changed files with 31 additions and 22 deletions

View File

@ -25,7 +25,6 @@
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
@ -62,8 +61,12 @@ 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_a = a;
const struct network_info *ni_b = b; const struct network_info *ni_b = b;
return util_timespec_compare(&ni_a->connected_time, if (l_time_after(ni_a->connected_time, ni_b->connected_time))
&ni_b->connected_time); return -1;
else if (l_time_before(ni_a->connected_time, ni_b->connected_time))
return 1;
return 0;
} }
static const char *known_network_get_path(const struct network_info *network) static const char *known_network_get_path(const struct network_info *network)
@ -219,7 +222,7 @@ static void known_network_update(struct network_info *orig_network,
const char *ssid, const char *ssid,
enum security security, enum security security,
struct l_settings *settings, struct l_settings *settings,
struct timespec *connected_time) uint64_t connected_time)
{ {
struct network_info *network; struct network_info *network;
bool is_hidden = false; bool is_hidden = false;
@ -234,7 +237,7 @@ static void known_network_update(struct network_info *orig_network,
network->ops = &known_network_ops; network->ops = &known_network_ops;
} }
if (util_timespec_compare(&network->connected_time, connected_time) && if (l_time_before(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),
@ -246,8 +249,7 @@ static void known_network_update(struct network_info *orig_network,
NULL); NULL);
} }
memcpy(&network->connected_time, connected_time, network->connected_time = connected_time;
sizeof(struct timespec));
l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden); l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden);
@ -493,11 +495,12 @@ static bool known_network_property_get_last_connected(struct l_dbus *dbus,
struct network_info *network = user_data; struct network_info *network = user_data;
char datestr[64]; char datestr[64];
struct tm tm; struct tm tm;
time_t seconds = l_time_to_secs(network->connected_time);
if (network->connected_time.tv_sec == 0) if (network->connected_time == 0)
return false; return false;
gmtime_r(&network->connected_time.tv_sec, &tm); gmtime_r(&seconds, &tm);
if (!strftime(datestr, sizeof(datestr), "%FT%TZ", &tm)) if (!strftime(datestr, sizeof(datestr), "%FT%TZ", &tm))
return false; return false;
@ -564,7 +567,7 @@ static void known_networks_watch_cb(const char *filename,
enum security security; enum security security;
struct network_info *network_before; struct network_info *network_before;
struct l_settings *settings; struct l_settings *settings;
struct timespec connected_time; uint64_t connected_time;
/* /*
* Ignore notifications for the actual directory, we can't do * Ignore notifications for the actual directory, we can't do
@ -595,11 +598,12 @@ static void known_networks_watch_cb(const char *filename,
*/ */
settings = storage_network_open(security, ssid); settings = storage_network_open(security, ssid);
if (settings && storage_network_get_mtime(security, ssid, if (settings) {
&connected_time) == 0) connected_time = l_path_get_mtime(full_path);
known_network_update(network_before, ssid, security, known_network_update(network_before, ssid, security,
settings, &connected_time); settings, connected_time);
else { } else {
if (network_before) if (network_before)
known_networks_remove(network_before); known_networks_remove(network_before);
} }
@ -803,7 +807,8 @@ static int known_networks_init(void)
const char *ssid; const char *ssid;
enum security security; enum security security;
struct l_settings *settings; struct l_settings *settings;
struct timespec connected_time; uint64_t connected_time;
L_AUTO_FREE_VAR(char *, full_path) = NULL;
if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK) if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
continue; continue;
@ -815,10 +820,14 @@ static int known_networks_init(void)
settings = storage_network_open(security, ssid); settings = storage_network_open(security, ssid);
if (settings && storage_network_get_mtime(security, ssid, full_path = storage_get_network_file_path(security, ssid);
&connected_time) == 0)
if (settings) {
connected_time = l_path_get_mtime(full_path);
known_network_update(NULL, ssid, security, settings, known_network_update(NULL, ssid, security, settings,
&connected_time); connected_time);
}
l_settings_free(settings); l_settings_free(settings);
} }

View File

@ -51,7 +51,7 @@ struct network_info {
char ssid[33]; char ssid[33];
enum security type; enum security type;
struct l_queue *known_frequencies; struct l_queue *known_frequencies;
struct timespec connected_time; /* Time last connected */ uint64_t connected_time; /* Time last connected */
int seen_count; /* Ref count for network.info */ int seen_count; /* Ref count for network.info */
bool is_hidden:1; bool is_hidden:1;
bool is_autoconnectable:1; bool is_autoconnectable:1;

View File

@ -194,7 +194,7 @@ bool network_rankmod(const struct network *network, double *rankmod)
* to at least once are autoconnectable. Known Networks that * to at least once are autoconnectable. Known Networks that
* we have never connected to are not. * we have never connected to are not.
*/ */
if (!network->info || !network->info->connected_time.tv_sec) if (!network->info || !network->info->connected_time)
return false; return false;
n = known_network_offset(network->info); n = known_network_offset(network->info);
@ -1322,7 +1322,7 @@ void network_rank_update(struct network *network, bool connected)
return; return;
} }
if (network->info->connected_time.tv_sec != 0) { if (network->info->connected_time != 0) {
int n = known_network_offset(network->info); int n = known_network_offset(network->info);
if (n >= (int) L_ARRAY_SIZE(rankmod_table)) if (n >= (int) L_ARRAY_SIZE(rankmod_table))