core: avoid assertion when removing devices

remove_device() is also called when the device has no longer a valid
ifindex and so device_is_wake_on_lan() must do an extra check to avoid
the following assertion:

 nmp_cache_lookup_entry_link: assertion 'ifindex > 0' failed

 0  _g_log_abort () from target:/lib64/libglib-2.0.so.0
 1  g_logv () from target:/lib64/libglib-2.0.so.0
 2  g_log () from target:/lib64/libglib-2.0.so.0
 3  nmp_cache_lookup_entry_link (cache=0xb858f0, ifindex=ifindex@entry=0) at ../src/platform/nmp-object.c:1713
 4  nmp_cache_lookup_link (cache=<optimized out>, ifindex=ifindex@entry=0) at ../src/platform/nmp-object.c:1728
 5  nm_platform_link_get_obj (self=self@entry=0xb85840, ifindex=ifindex@entry=0, visible_only=visible_only@entry=1) at ../src/platform/nm-platform.c:759
 6  nm_platform_link_get (self=self@entry=0xb85840, ifindex=ifindex@entry=0) at ../src/platform/nm-platform.c:784
 7  nm_platform_link_get_type (self=self@entry=0xb85840, ifindex=ifindex@entry=0) at ../src/platform/nm-platform.c:1065
 8  link_get_wake_on_lan (platform=0xb85840, ifindex=0) at ../src/platform/nm-linux-platform.c:6963
 9  nm_platform_link_get_wake_on_lan (self=self@entry=0xb85840, ifindex=0) at ../src/platform/nm-platform.c:1705
 10 device_is_wake_on_lan (platform=0xb85840, device=<optimized out>) at ../src/nm-manager.c:1617
 11 remove_device (self=0xbd0060, device=<optimized out>, device@entry=0xd298c0, quitting=quitting@entry=0, allow_unmanage=allow_unmanage@entry=1)
 12 device_removed_cb (device=0xd298c0, user_data=0xbd0060) at ../src/nm-manager.c:1698
 13 _g_closure_invoke_va () from target:/lib64/libgobject-2.0.so.0
 14 g_signal_emit_valist () from target:/lib64/libgobject-2.0.so.0
 15 g_signal_emit () from target:/lib64/libgobject-2.0.so.0
 16 available_connections_check_delete_unrealized_on_idle (user_data=0xd298c0) at ../src/devices/nm-device.c:4446

Fixes: ca3bbede74
(cherry picked from commit 92e57ab292)
This commit is contained in:
Beniamino Galvani 2018-12-04 19:05:27 +01:00
parent 9135603c93
commit 02eb4bfa9d

View file

@ -1596,7 +1596,12 @@ again:
static gboolean
device_is_wake_on_lan (NMPlatform *platform, NMDevice *device)
{
return nm_platform_link_get_wake_on_lan (platform, nm_device_get_ip_ifindex (device));
int ifindex;
ifindex = nm_device_get_ip_ifindex (device);
if (ifindex <= 0)
return FALSE;
return nm_platform_link_get_wake_on_lan (platform, ifindex);
}
static void