diff --git a/src/nm-device.c b/src/nm-device.c index 3153e2d901..ef874ebfae 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -59,6 +59,7 @@ #include "nm-firewall-manager.h" #include "nm-properties-changed-signal.h" #include "nm-enum-types.h" +#include "nm-settings-connection.h" static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context); @@ -4134,6 +4135,15 @@ nm_device_state_changed (NMDevice *device, /* Cache the activation request for the dispatcher */ req = priv->act_request ? g_object_ref (priv->act_request) : NULL; + /* Update connection timestamps; do this before possibly deactivating the + * device since that will clear the activation request and thus the + * connection, which we need. + */ + if (state == NM_DEVICE_STATE_ACTIVATED || old_state == NM_DEVICE_STATE_ACTIVATED) { + nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)), + (guint64) time (NULL), TRUE); + } + /* Handle the new state here; but anything that could trigger * another state change should be done below. */ diff --git a/src/nm-manager.c b/src/nm-manager.c index 6760d978e0..010e30ce64 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -350,7 +350,7 @@ vpn_manager_connection_activated_cb (NMVPNManager *manager, { /* Update timestamp for the VPN connection */ nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_vpn_connection_get_connection (vpn)), - (guint64) time (NULL)); + (guint64) time (NULL), TRUE); } static void @@ -471,15 +471,6 @@ manager_device_state_changed (NMDevice *device, } nm_manager_update_state (manager); - - if (new_state == NM_DEVICE_STATE_ACTIVATED) { - NMActRequest *req; - - req = nm_device_get_act_request (device); - if (req) - nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)), - (guint64) time (NULL)); - } } /* Removes a device from a device list; returns the start of the new device list */ @@ -3929,7 +3920,7 @@ periodic_update_active_connection_timestamps (gpointer user_data) req = nm_manager_get_act_request_by_path (manager, active_path, &device); if (device && nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)), - (guint64) time (NULL)); + (guint64) time (NULL), FALSE); else { /* The connection is probably VPN */ NMVPNConnection *vpn_con; @@ -3937,7 +3928,7 @@ periodic_update_active_connection_timestamps (gpointer user_data) vpn_con = nm_vpn_manager_get_vpn_connection_for_active (priv->vpn_manager, active_path); if (vpn_con && nm_vpn_connection_get_vpn_state (vpn_con) == NM_VPN_CONNECTION_STATE_ACTIVATED) nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_vpn_connection_get_connection (vpn_con)), - (guint64) time (NULL)); + (guint64) time (NULL), FALSE); } } diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 5c4ba6428d..5d240c7778 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1422,11 +1422,14 @@ nm_settings_connection_get_timestamp (NMSettingsConnection *connection) * @connection: the #NMSettingsConnection * @timestamp: timestamp to set into the connection and to store into * the timestamps database + * @flush_to_disk: if %TRUE, commit timestamp update to persistent storage * * Updates the connection and timestamps database with the provided timestamp. **/ void -nm_settings_connection_update_timestamp (NMSettingsConnection *connection, guint64 timestamp) +nm_settings_connection_update_timestamp (NMSettingsConnection *connection, + guint64 timestamp, + gboolean flush_to_disk) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); const char *connection_uuid; @@ -1438,6 +1441,9 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *connection, guint /* Update timestamp in private storage */ priv->timestamp = timestamp; + if (flush_to_disk == FALSE) + return; + /* Save timestamp to timestamps database file */ timestamps_file = g_key_file_new (); if (!g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) { diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index bc9e3c4712..077a145d04 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -124,7 +124,9 @@ void nm_settings_connection_signal_remove (NMSettingsConnection *self); guint64 nm_settings_connection_get_timestamp (NMSettingsConnection *connection); -void nm_settings_connection_update_timestamp (NMSettingsConnection *connection, guint64 timestamp); +void nm_settings_connection_update_timestamp (NMSettingsConnection *connection, + guint64 timestamp, + gboolean flush_to_disk); void nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *connection);