diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index c5824d73c6..8d646d3506 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -754,4 +754,90 @@ nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max } +static gint64 monotonic_timestamp_offset_sec; + +static void +monotonic_timestamp_get (struct timespec *tp) +{ + static gboolean initialized = FALSE; + int err; + + err = clock_gettime (CLOCK_BOOTTIME, tp); + + g_assert (err == 0); (void)err; + g_assert (tp->tv_nsec >= 0 && tp->tv_nsec < NM_UTILS_NS_PER_SECOND); + + if (G_LIKELY (initialized)) + return; + + /* Calculate an offset for the time stamp. + * + * We always want positive values, because then we can initialize + * a timestamp with 0 and be sure, that it will be less then any + * value nm_utils_get_monotonic_timestamp_*() might return. + * For this to be true also for nm_utils_get_monotonic_timestamp_s() at + * early boot, we have to shift the timestamp to start counting at + * least from 1 second onward. + * + * Another advantage of shifting is, that this way we make use of the whole 31 bit + * range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_s() + * wraps (~68 years). + **/ + monotonic_timestamp_offset_sec = (- ((gint64) tp->tv_sec)) + 1; + initialized = TRUE; + + if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) { + time_t now = time (NULL); + struct tm tm; + char s[255]; + + strftime (s, sizeof (s), "%Y-%m-%d %H:%M:%S", localtime_r (&now, &tm)); + nm_log_dbg (LOGD_CORE, "monotonic timestamp starts counting with 1.%09ld seconds at " + "CLOCK_BOOTTIME=%lld.%09ld (local time is %s)", + tp->tv_nsec, (long long)tp->tv_sec, tp->tv_nsec, s); + } +} + +/** + * nm_utils_get_monotonic_timestamp_ms: + * + * Returns: a monotonically increasing time stamp in milliseconds, + * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. + * + * The returned value will start counting at an undefined point + * in the past and will always be positive. + **/ +gint64 +nm_utils_get_monotonic_timestamp_ms (void) +{ + struct timespec tp; + + monotonic_timestamp_get (&tp); + + /* Although the result will always be positive, we return a signed + * integer, which makes it easier to calculate time differences (when + * you want to subtract signed values). + **/ + return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec) * ((gint64) 1000) + + (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/1000)); +} + +/** + * nm_utils_get_monotonic_timestamp_s: + * + * Returns: nm_utils_get_monotonic_timestamp_ms() in seconds (throwing + * away sub second parts). The returned value will always be positive. + * + * This value wraps after roughly 68 years which should be fine for any + * practical purpose. + **/ +gint32 +nm_utils_get_monotonic_timestamp_s (void) +{ + struct timespec tp; + + monotonic_timestamp_get (&tp); + return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec); +} + diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 7e62b71aed..cae7944e08 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -96,4 +96,8 @@ NMConnection *nm_utils_match_connection (GSList *connections, gint64 nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback); +#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000) +gint64 nm_utils_get_monotonic_timestamp_ms (void); +gint32 nm_utils_get_monotonic_timestamp_s (void); + #endif /* NETWORK_MANAGER_UTILS_H */ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 47868f9180..a6279a4cb5 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -104,7 +104,7 @@ typedef struct { /* PPPoE */ NMPPPManager *ppp_manager; NMIP4Config *pending_ip4_config; - time_t last_pppoe_time; + gint32 last_pppoe_time; guint pppoe_wait_id; } NMDeviceEthernetPrivate; @@ -949,11 +949,11 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) * get confused and fail to negotiate the new connection. (rh #1023503) */ if (priv->last_pppoe_time) { - time_t delay = time (NULL) - priv->last_pppoe_time; + gint32 delay = nm_utils_get_monotonic_timestamp_s () - priv->last_pppoe_time; if (delay < PPPOE_RECONNECT_DELAY && device_get_setting (dev, NM_TYPE_SETTING_PPPOE)) { - nm_log_info (LOGD_DEVICE, "(%s) delaying PPPoE reconnect to ensure peer is ready...", - nm_device_get_iface (dev)); + nm_log_info (LOGD_DEVICE, "(%s) delaying PPPoE reconnect for %d seconds to ensure peer is ready...", + nm_device_get_iface (dev), delay); g_assert (!priv->pppoe_wait_id); priv->pppoe_wait_id = g_timeout_add_seconds (delay, pppoe_reconnect_delay, @@ -1219,7 +1219,7 @@ deactivate (NMDevice *device) /* Set last PPPoE connection time */ if (device_get_setting (device, NM_TYPE_SETTING_PPPOE)) - NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = time (NULL); + NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = nm_utils_get_monotonic_timestamp_s (); /* Reset MAC address back to initial address */ nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_ETHER); diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c index e91214e162..c1102bf303 100644 --- a/src/devices/nm-device-wifi.c +++ b/src/devices/nm-device-wifi.c @@ -142,7 +142,7 @@ struct _NMDeviceWifiPrivate { guint32 rate; gboolean enabled; /* rfkilled or not */ - time_t scheduled_scan_time; + gint32 scheduled_scan_time; guint8 scan_interval; /* seconds */ guint pending_scan_id; guint scanlist_cull_id; @@ -1438,7 +1438,7 @@ impl_device_request_scan (NMDeviceWifi *self, { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self); - time_t last_scan; + gint32 last_scan; GError *error; if ( !priv->enabled @@ -1459,7 +1459,7 @@ impl_device_request_scan (NMDeviceWifi *self, } last_scan = nm_supplicant_interface_get_last_scan_time (priv->supplicant.iface); - if ((time (NULL) - last_scan) < 10) { + if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) { error = g_error_new_literal (NM_WIFI_ERROR, NM_WIFI_ERROR_SCAN_NOT_ALLOWED, "Scanning not allowed immediately following previous scan"); @@ -1709,7 +1709,7 @@ static void schedule_scan (NMDeviceWifi *self, gboolean backoff) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - time_t now = time (NULL); + gint32 now = nm_utils_get_monotonic_timestamp_s (); /* Cancel the pending scan if it would happen later than (now + the scan_interval) */ if (priv->pending_scan_id) { @@ -1897,7 +1897,7 @@ static gboolean cull_scan_list (NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - time_t now = time (NULL); + gint32 now = nm_utils_get_monotonic_timestamp_s (); GSList *outdated_list = NULL; GSList *elt; guint32 removed = 0, total = 0; @@ -1913,6 +1913,7 @@ cull_scan_list (NMDeviceWifi *self) for (elt = priv->ap_list; elt; elt = g_slist_next (elt), total++) { NMAccessPoint *ap = elt->data; const guint prune_interval_s = SCAN_INTERVAL_MAX * 3; + gint32 last_seen; /* Don't cull the associated AP or manually created APs */ if (ap == priv->current_ap) @@ -1930,7 +1931,8 @@ cull_scan_list (NMDeviceWifi *self) && g_object_get_data (G_OBJECT (ap), WPAS_REMOVED_TAG) == NULL) continue; - if (nm_ap_get_last_seen (ap) + prune_interval_s < now) + last_seen = nm_ap_get_last_seen (ap); + if (!last_seen || last_seen + prune_interval_s < now) outdated_list = g_slist_prepend (outdated_list, ap); } @@ -2036,7 +2038,7 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, /* Update the AP's last-seen property */ ap = get_ap_by_supplicant_path (self, object_path); if (ap) - nm_ap_set_last_seen (ap, (guint32) time (NULL)); + nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); /* Remove outdated access points */ schedule_scanlist_cull (self); diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index c2a760ea36..5b3b3f8ea6 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -28,6 +28,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-logging.h" #include "nm-dbus-glib-types.h" @@ -802,16 +803,6 @@ nm_dhcp_client_foreach_option (NMDHCPClient *self, return TRUE; } -static guint32 -get_time (void) -{ - struct timespec tp; - - clock_gettime (CLOCK_MONOTONIC, &tp); - - return tp.tv_sec; -} - /********************************************/ static gboolean @@ -1163,7 +1154,7 @@ ip4_options_to_config (NMDHCPClient *self) ip4_config = nm_ip4_config_new (); memset (&address, 0, sizeof (address)); - address.timestamp = get_time (); + address.timestamp = nm_utils_get_monotonic_timestamp_s (); str = g_hash_table_lookup (priv->options, "new_ip_address"); if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { @@ -1395,7 +1386,7 @@ ip6_options_to_config (NMDHCPClient *self) memset (&address, 0, sizeof (address)); address.plen = 128; - address.timestamp = get_time (); + address.timestamp = nm_utils_get_monotonic_timestamp_s (); priv = NM_DHCP_CLIENT_GET_PRIVATE (self); g_return_val_if_fail (priv->options != NULL, NULL); diff --git a/src/nm-netlink-monitor.c b/src/nm-netlink-monitor.c index 89f3b8093f..1e8d8b3726 100644 --- a/src/nm-netlink-monitor.c +++ b/src/nm-netlink-monitor.c @@ -46,6 +46,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-netlink-monitor.h" #include "nm-logging.h" @@ -107,18 +108,18 @@ detach_monitor (gpointer data) static void log_error_limited (NMNetlinkMonitor *monitor, guint32 code, const char *fmt, ...) { - static time_t rl_time = 0; + static gint64 rl_time = -10001; static guint32 rl_code = 0; static guint32 rl_count = 0; va_list args; char *msg; - time_t now; + gint64 now; g_return_if_fail (monitor != NULL); - now = time (NULL); + now = nm_utils_get_monotonic_timestamp_ms (); - if ((code != rl_code) || (now > rl_time + 10)) { + if (code != rl_code || now > rl_time + 10000) { va_start (args, fmt); msg = g_strdup_vprintf (fmt, args); va_end (args); diff --git a/src/nm-policy.c b/src/nm-policy.c index bd1d58a4e6..34216c8717 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1252,13 +1252,13 @@ reset_connections_retries (gpointer user_data) NMPolicy *policy = (NMPolicy *) user_data; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); GSList *connections, *iter; - time_t con_stamp, min_stamp, now; + gint32 con_stamp, min_stamp, now; gboolean changed = FALSE; priv->reset_retries_id = 0; min_stamp = 0; - now = time (NULL); + now = nm_utils_get_monotonic_timestamp_s (); connections = nm_settings_get_connections (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMSettingsConnection *connection = NM_SETTINGS_CONNECTION (iter->data); @@ -1429,10 +1429,10 @@ device_state_changed (NMDevice *device, nm_connection_get_id (NM_CONNECTION (connection))); /* Schedule a handler to reset retries count */ if (!priv->reset_retries_id) { - time_t retry_time = nm_settings_connection_get_autoconnect_retry_time (connection); + gint32 retry_time = nm_settings_connection_get_autoconnect_retry_time (connection); g_warn_if_fail (retry_time != 0); - priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - time (NULL)), reset_connections_retries, policy); + priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, policy); } } nm_connection_clear_secrets (NM_CONNECTION (connection)); diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c index b7af653289..c68d808c17 100644 --- a/src/nm-wifi-ap.c +++ b/src/nm-wifi-ap.c @@ -59,7 +59,7 @@ typedef struct gboolean fake; /* Whether or not the AP is from a scan */ gboolean hotspot; /* Whether the AP is a local device's hotspot network */ gboolean broadcast; /* Whether or not the AP is broadcasting (hidden) */ - glong last_seen; /* Last time the AP was seen in a scan in seconds */ + gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via nm_utils_get_monotonic_timestamp_s()) */ } NMAccessPointPrivate; #define NM_AP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP, NMAccessPointPrivate)) @@ -504,7 +504,7 @@ nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties) return NULL; } - nm_ap_set_last_seen (ap, (guint32) time (NULL)); + nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); if (!nm_ap_get_ssid (ap)) nm_ap_set_broadcast (ap, FALSE); @@ -745,7 +745,7 @@ nm_ap_dump (NMAccessPoint *ap, const char *prefix) nm_log_dbg (LOGD_WIFI_SCAN, " quality %d", priv->strength); nm_log_dbg (LOGD_WIFI_SCAN, " frequency %d", priv->freq); nm_log_dbg (LOGD_WIFI_SCAN, " max rate %d", priv->max_bitrate); - nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %ld", priv->last_seen); + nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %d", (int) priv->last_seen); } const char * @@ -1095,14 +1095,16 @@ void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast) * APs older than a certain date are dropped from the list. * */ -glong nm_ap_get_last_seen (const NMAccessPoint *ap) +gint32 +nm_ap_get_last_seen (const NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_AP (ap), FALSE); return NM_AP_GET_PRIVATE (ap)->last_seen; } -void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen) +void +nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen) { g_return_if_fail (NM_IS_AP (ap)); diff --git a/src/nm-wifi-ap.h b/src/nm-wifi-ap.h index be650f6c28..f51fa078ee 100644 --- a/src/nm-wifi-ap.h +++ b/src/nm-wifi-ap.h @@ -101,8 +101,8 @@ void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake); gboolean nm_ap_get_broadcast (NMAccessPoint *ap); void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast); -glong nm_ap_get_last_seen (const NMAccessPoint *ap); -void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen); +gint32 nm_ap_get_last_seen (const NMAccessPoint *ap); +void nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen); gboolean nm_ap_check_compatible (NMAccessPoint *self, NMConnection *connection); diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 9fa4077fdf..43944721cd 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -23,6 +23,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-fake-platform.h" #include "nm-logging.h" @@ -728,16 +729,6 @@ ip6_address_get_all (NMPlatform *platform, int ifindex) return addresses; } -static guint32 -get_time (void) -{ - struct timespec tp; - - clock_gettime (CLOCK_MONOTONIC, &tp); - - return tp.tv_sec; -} - static gboolean ip4_address_add (NMPlatform *platform, int ifindex, in_addr_t addr, in_addr_t peer_addr, @@ -752,7 +743,7 @@ ip4_address_add (NMPlatform *platform, int ifindex, address.address = addr; address.peer_address = peer_addr; address.plen = plen; - address.timestamp = get_time (); + address.timestamp = nm_utils_get_monotonic_timestamp_s (); address.lifetime = lifetime; address.preferred = preferred; @@ -791,7 +782,7 @@ ip6_address_add (NMPlatform *platform, int ifindex, address.address = addr; address.peer_address = peer_addr; address.plen = plen; - address.timestamp = get_time (); + address.timestamp = nm_utils_get_monotonic_timestamp_s (); address.lifetime = lifetime; address.preferred = preferred; address.flags = flags; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index d99cb1d580..9fc264aeb6 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -43,6 +43,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-linux-platform.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" @@ -814,16 +815,6 @@ hack_empty_master_iff_lower_up (NMPlatform *platform, struct nl_object *object) rtnl_link_unset_flags (rtnllink, IFF_LOWER_UP); } -static guint32 -get_time (void) -{ - struct timespec tp; - - clock_gettime (CLOCK_MONOTONIC, &tp); - - return tp.tv_sec; -} - static void init_ip4_address (NMPlatformIP4Address *address, struct rtnl_addr *rtnladdr) { @@ -836,7 +827,7 @@ init_ip4_address (NMPlatformIP4Address *address, struct rtnl_addr *rtnladdr) address->ifindex = rtnl_addr_get_ifindex (rtnladdr); address->plen = rtnl_addr_get_prefixlen (rtnladdr); - address->timestamp = get_time (); + address->timestamp = nm_utils_get_monotonic_timestamp_s (); address->lifetime = rtnl_addr_get_valid_lifetime (rtnladdr); address->preferred = rtnl_addr_get_preferred_lifetime (rtnladdr); g_assert (nl_addr_get_len (nladdr) == sizeof (address->address)); @@ -857,7 +848,7 @@ init_ip6_address (NMPlatformIP6Address *address, struct rtnl_addr *rtnladdr) address->ifindex = rtnl_addr_get_ifindex (rtnladdr); address->plen = rtnl_addr_get_prefixlen (rtnladdr); - address->timestamp = get_time (); + address->timestamp = nm_utils_get_monotonic_timestamp_s (); address->lifetime = rtnl_addr_get_valid_lifetime (rtnladdr); address->preferred = rtnl_addr_get_preferred_lifetime (rtnladdr); address->flags = rtnl_addr_get_flags (rtnladdr); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 79eb06523a..5d6257fd85 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -26,6 +26,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-platform.h" #include "NetworkManagerUtils.h" #include "nm-logging.h" @@ -1339,16 +1340,6 @@ array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address return FALSE; } -static guint32 -get_time (void) -{ - struct timespec tp; - - clock_gettime (CLOCK_MONOTONIC, &tp); - - return tp.tv_sec; -} - /* Compute (a - b) in an overflow-safe manner. */ static guint32 subtract_guint32 (guint32 a, guint32 b) @@ -1375,7 +1366,7 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses) { GArray *addresses; NMPlatformIP4Address *address; - guint32 now = get_time (); + guint32 now = nm_utils_get_monotonic_timestamp_s (); int i; /* Delete unknown addresses */ @@ -1428,7 +1419,7 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses) { GArray *addresses; NMPlatformIP6Address *address; - guint32 now = get_time (); + guint32 now = nm_utils_get_monotonic_timestamp_s (); int i; /* Delete unknown addresses */ diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index a219a3794c..4ae64dbc13 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -133,6 +133,10 @@ typedef enum { NM_PLATFORM_SOURCE_USER, } NMPlatformSource; +/** + * NMPlatformIP4Address: + * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s() + **/ typedef struct { int ifindex; NMPlatformSource source; @@ -144,6 +148,10 @@ typedef struct { guint32 preferred; /* seconds */ } NMPlatformIP4Address; +/** + * NMPlatformIP6Address: + * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s() + **/ typedef struct { int ifindex; NMPlatformSource source; diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c index e7124f1b7a..5fb28778fc 100644 --- a/src/rdisc/nm-lndp-rdisc.c +++ b/src/rdisc/nm-lndp-rdisc.c @@ -26,6 +26,7 @@ #include "nm-lndp-rdisc.h" +#include "NetworkManagerUtils.h" #include "nm-logging.h" #define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__) @@ -384,20 +385,10 @@ check_timestamps (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed) } } -static guint32 -get_time (void) -{ - struct timespec tp; - - clock_gettime (CLOCK_MONOTONIC, &tp); - - return tp.tv_sec; -} - static gboolean timeout_cb (gpointer user_data) { - check_timestamps (user_data, get_time (), 0); + check_timestamps (user_data, nm_utils_get_monotonic_timestamp_s (), 0); return TRUE; } @@ -470,7 +461,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) const char *lladdr = NULL; struct ndp_msgra *msgra = ndp_msgra (msg); NMRDiscGateway gateway; - guint32 now = get_time (); + guint32 now = nm_utils_get_monotonic_timestamp_s (); int offset; if (rdisc->lladdr) diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am index 7308cfe973..9d21284c70 100644 --- a/src/rdisc/tests/Makefile.am +++ b/src/rdisc/tests/Makefile.am @@ -1,15 +1,24 @@ AM_CPPFLAGS = \ -I${top_srcdir} \ + -I$(top_srcdir)/include \ -I${top_srcdir}/src \ + -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/logging \ + -I${top_srcdir}/src/platform \ + -I${top_srcdir}/src/posix-signals \ -I${top_srcdir}/libnm-util \ -I${srcdir}/.. \ $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(POLKIT_CFLAGS) \ $(LIBNL_CFLAGS) \ $(LIBNDP_CFLAGS) AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) -AM_LDFLAGS = $(GLIB_LIBS) $(CODE_COVERAGE_LDFLAGS) +AM_LDFLAGS = \ + $(GLIB_LIBS) \ + $(DBUS_LIBS) \ + $(CODE_COVERAGE_LDFLAGS) @GNOME_CODE_COVERAGE_RULES@ @@ -17,9 +26,8 @@ noinst_PROGRAMS = \ rdisc rdisc_SOURCES = \ - rdisc.c \ - ../nm-rdisc.c \ - ../nm-fake-rdisc.c \ - ../nm-lndp-rdisc.c \ - ../../logging/nm-logging.c -rdisc_LDADD = $(LIBNDP_LIBS) + rdisc.c +rdisc_LDADD = \ + $(top_builddir)/src/libNetworkManager.la \ + $(LIBNDP_LIBS) + diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 2a23396759..aac267e7a3 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -126,7 +126,7 @@ typedef struct { GHashTable *seen_bssids; /* Up-to-date BSSIDs that's been seen for the connection */ int autoconnect_retries; - time_t autoconnect_retry_time; + gint32 autoconnect_retry_time; NMDeviceStateReason autoconnect_blocked_reason; } NMSettingsConnectionPrivate; @@ -1923,7 +1923,7 @@ nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *connection if (retries) priv->autoconnect_retry_time = 0; else - priv->autoconnect_retry_time = time (NULL) + AUTOCONNECT_RESET_RETRIES_TIMER; + priv->autoconnect_retry_time = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER; } void @@ -1932,7 +1932,7 @@ nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connecti nm_settings_connection_set_autoconnect_retries (connection, AUTOCONNECT_RETRIES_DEFAULT); } -time_t +gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection) { return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_retry_time; diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index d79c62d912..5a84349746 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -154,7 +154,7 @@ void nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *conne int retries); void nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connection); -time_t nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection); +gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection); NMDeviceStateReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *connection); void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *connection, diff --git a/src/supplicant-manager/nm-supplicant-interface.c b/src/supplicant-manager/nm-supplicant-interface.c index 4063085c3b..789039c7a9 100644 --- a/src/supplicant-manager/nm-supplicant-interface.c +++ b/src/supplicant-manager/nm-supplicant-interface.c @@ -24,6 +24,7 @@ #include #include +#include "NetworkManagerUtils.h" #include "nm-supplicant-interface.h" #include "nm-supplicant-manager.h" #include "nm-logging.h" @@ -106,7 +107,7 @@ typedef struct { guint32 blobs_left; GHashTable * bss_proxies; - time_t last_scan; + gint32 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_s() */ NMSupplicantConfig * cfg; @@ -167,7 +168,7 @@ bss_properties_changed (DBusGProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (priv->scanning) - priv->last_scan = time (NULL); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); if (g_strcmp0 (interface, WPAS_DBUS_IFACE_BSS) == 0) g_signal_emit (self, signals[BSS_UPDATED], 0, dbus_g_proxy_get_path (proxy), props); @@ -230,7 +231,7 @@ wpas_iface_bss_added (DBusGProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (priv->scanning) - priv->last_scan = time (NULL); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); handle_new_bss (self, object_path, props); } @@ -334,7 +335,7 @@ set_state (NMSupplicantInterface *self, guint32 new_state) if ( priv->state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING || old_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING) - priv->last_scan = time (NULL); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); /* Disconnect reason is no longer relevant when not in the DISCONNECTED state */ if (priv->state != NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED) @@ -367,7 +368,7 @@ set_scanning (NMSupplicantInterface *self, gboolean new_scanning) /* Cache time of last scan completion */ if (priv->scanning == FALSE) - priv->last_scan = time (NULL); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); g_object_notify (G_OBJECT (self), "scanning"); } @@ -388,7 +389,7 @@ nm_supplicant_interface_get_scanning (NMSupplicantInterface *self) return FALSE; } -time_t +gint32 nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self) { return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->last_scan; @@ -403,7 +404,7 @@ wpas_iface_scan_done (DBusGProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* Cache last scan completed time */ - priv->last_scan = time (NULL); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); g_signal_emit (self, signals[SCAN_DONE], 0, success); } diff --git a/src/supplicant-manager/nm-supplicant-interface.h b/src/supplicant-manager/nm-supplicant-interface.h index 2f0233cf78..633c16cc56 100644 --- a/src/supplicant-manager/nm-supplicant-interface.h +++ b/src/supplicant-manager/nm-supplicant-interface.h @@ -144,7 +144,7 @@ const char *nm_supplicant_interface_state_to_string (guint32 state); gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self); -time_t nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self); +gint32 nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self); const char *nm_supplicant_interface_get_ifname (NMSupplicantInterface *self);