From 5e4d13271cfa5d13f7d847a2cdd269cd11cb56cd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 Feb 2017 16:22:57 +0100 Subject: [PATCH] device/wifi: ensure consistent timestamp for dumping Wi-Fi AP When we dump a list of APs, determine one timestamp for "now", instead of re-evaluating it every time. This ensures that all APs are printed with the same understanding of the current timestamp. --- src/devices/wifi/nm-device-wifi.c | 18 ++++++++++-------- src/devices/wifi/nm-wifi-ap.c | 5 +++-- src/devices/wifi/nm-wifi-ap.h | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 6ebca18c67..44d2ab6096 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -198,14 +198,15 @@ static void _hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset); static void _ap_dump (NMDeviceWifi *self, const NMWifiAP *ap, - const char *prefix) + const char *prefix, + gint32 now_s) { char buf[1024]; buf[0] = '\0'; _LOGD (LOGD_WIFI_SCAN, "wifi-ap: %-7s %s", prefix, - nm_wifi_ap_to_string (ap, buf, sizeof (buf))); + nm_wifi_ap_to_string (ap, buf, sizeof (buf), now_s)); } static void @@ -1568,14 +1569,15 @@ ap_list_dump (gpointer user_data) if (_LOGD_ENABLED (LOGD_WIFI_SCAN)) { gs_free NMWifiAP **list = NULL; gsize i; + gint32 now_s = nm_utils_get_monotonic_timestamp_s (); _LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%u next:%u]", - nm_utils_get_monotonic_timestamp_s (), + now_s, priv->last_scan, priv->scheduled_scan_time); list = ap_list_get_sorted (self, TRUE); for (i = 0; list[i]; i++) - _ap_dump (self, list[i], "dump"); + _ap_dump (self, list[i], "dump", now_s); } return G_SOURCE_REMOVE; } @@ -1673,10 +1675,10 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, found_ap = get_ap_by_supplicant_path (self, object_path); if (found_ap) { - _ap_dump (self, ap, "updated"); + _ap_dump (self, ap, "updated", 0); nm_wifi_ap_update_from_properties (found_ap, object_path, properties); } else { - _ap_dump (self, ap, "added"); + _ap_dump (self, ap, "added", 0); ap_add_remove (self, ACCESS_POINT_ADDED, ap, TRUE); } @@ -1711,7 +1713,7 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, ap = get_ap_by_supplicant_path (self, object_path); if (ap) { - _ap_dump (self, ap, "updated"); + _ap_dump (self, ap, "updated", 0); nm_wifi_ap_update_from_properties (ap, object_path, properties); schedule_ap_list_dump (self); } @@ -1739,7 +1741,7 @@ supplicant_iface_bss_removed_cb (NMSupplicantInterface *iface, */ nm_wifi_ap_set_fake (ap, TRUE); } else { - _ap_dump (self, ap, "removed"); + _ap_dump (self, ap, "removed", 0); ap_add_remove (self, ACCESS_POINT_REMOVED, ap, TRUE); schedule_ap_list_dump (self); } diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 702e5e8c31..96e9d19c5f 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -578,7 +578,8 @@ add_group_ciphers (NMWifiAP *ap, NMSettingWirelessSecurity *sec) const char * nm_wifi_ap_to_string (const NMWifiAP *self, char *str_buf, - gulong buf_len) + gulong buf_len, + gint32 now_s) { const NMWifiAPPrivate *priv; const char *supplicant_id = "-"; @@ -609,7 +610,7 @@ nm_wifi_ap_to_string (const NMWifiAP *self, priv->flags & NM_802_11_AP_FLAGS_PRIVACY ? 'P' : '_', priv->wpa_flags & 0xFFFF, priv->rsn_flags & 0xFFFF, - priv->last_seen > 0 ? (nm_utils_get_monotonic_timestamp_s () - priv->last_seen) : -1, + priv->last_seen > 0 ? ((now_s > 0 ? now_s : nm_utils_get_monotonic_timestamp_s ()) - priv->last_seen) : -1, supplicant_id); return str_buf; } diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index 818e651dbc..a68aece8a8 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -91,6 +91,7 @@ void nm_wifi_ap_set_fake (NMWifiAP *ap, const char *nm_wifi_ap_to_string (const NMWifiAP *self, char *str_buf, - gulong buf_len); + gulong buf_len, + gint32 now_s); #endif /* __NM_WIFI_AP_H__ */