Update connectivity value on device removal

When a device is removed (like when the user unplugs a usb network
device) the device object is removed, so it doesn't emit a notify signal
for a change in its connectivity and so, device_connectivity_changed
is not called. This means that nobody updates the global connectivity
value which is potentially wrong if the device was the one providing
network connectivity.

Since device_connectivity_changed's first two parameters aren't actually
used and are there just for the signal to be able to be connected, I
moved the code from device_connectivity_changed to a new
update_connectivity_value function that just takes a NMManager
parameter and also call it from remove_device.

[thaller@redhat.com: fix coding style regarding whitespace]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/141

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/101
This commit is contained in:
Antonio Larrosa
2019-03-21 11:32:32 +01:00
committed by Thomas Haller
parent aba01d3d8a
commit e504b7fc96

View File

@@ -303,6 +303,8 @@ static const GDBusSignalInfo signal_info_state_changed;
static const GDBusSignalInfo signal_info_device_added;
static const GDBusSignalInfo signal_info_device_removed;
static void update_connectivity_value (NMManager *self);
static gboolean add_device (NMManager *self, NMDevice *device, GError **error);
static void _emit_device_added_removed (NMManager *self,
@@ -1700,6 +1702,8 @@ remove_device (NMManager *self,
g_signal_emit (self, signals[INTERNAL_DEVICE_REMOVED], 0, device);
_notify (self, PROP_ALL_DEVICES);
update_connectivity_value (self);
nm_dbus_object_clear_and_unexport (&device);
check_if_startup_complete (self);
@@ -2923,6 +2927,12 @@ static void
device_connectivity_changed (NMDevice *device,
GParamSpec *pspec,
NMManager *self)
{
update_connectivity_value (self);
}
static void
update_connectivity_value (NMManager *self)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMConnectivityState best_state;